Replies: 2 comments 3 replies
-
@RutgerLit import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(0) |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can use the CTkScalingBaseClass, but currently this exists only in the develop branch: import customtkinter
from customtkinter.windows.widgets.scaling.scaling_base_class import CTkScalingBaseClass
import tkinter
class ScalableTkButton(tkinter.Button, CTkScalingBaseClass):
def __init__(self,
*args,
width: int = 0,
height: int = 1,
font: tuple = ("TkDefaultFont", -12, ""),
**kwargs):
tkinter.Button.__init__(self, *args, **kwargs)
CTkScalingBaseClass.__init__(self, scaling_type="widget")
self._width = width
self._height = height
self._font = font
super().configure(width=round(self._apply_widget_scaling(self._width)),
height=round(self._apply_widget_scaling(self._height)),
font=self._apply_font_scaling(self._font))
def _set_scaling(self, new_widget_scaling, new_window_scaling):
CTkScalingBaseClass._set_scaling(self, new_widget_scaling, new_window_scaling)
super().configure(width=round(self._apply_widget_scaling(self._width)),
height=round(self._apply_widget_scaling(self._height)),
font=self._apply_font_scaling(self._font))
def configure(self, **kwargs):
if "width" in kwargs:
self._width = kwargs.pop("width")
super().configure(width=round(self._apply_widget_scaling(self._width)))
if "height" in kwargs:
self._width = kwargs.pop("height")
super().configure(height=round(self._apply_widget_scaling(self._height)))
if "font" in kwargs:
self._width = kwargs.pop("font")
super().configure(font=self._apply_font_scaling(self._font))
super().configure(**kwargs)
def set_scaling(scaling):
customtkinter.set_widget_scaling(scaling)
customtkinter.set_window_scaling(scaling)
app = customtkinter.CTk()
scaling_button = customtkinter.CTkSegmentedButton(app, values=[0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.5, 2.0], command=set_scaling)
scaling_button.pack(pady=10)
button_1 = ScalableTkButton(app, text="ScalableTkButton")
button_1.pack(pady=10)
app.mainloop() Every argument of the Tk widget you want to scale, has to be stored separately from the Tk widget. Then you can apply the widget scaling or font scaling methods you get from the CTkScalingBaseClass. The |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Tom,
Thank you for the great product, it's awesome!
I have a question about scaling on a Windows pc.
If I drag a ctk window to my other monitor (with a different scaling than my main monitor), I see that ctk nicely takes the scaling of the new monitor into account. I can also see this because the method "update_scaling_callbacks_for_window" in the file "scaling_tracker.py" is called. So that is very nice!
But I also have some regular tkinter widgets in my app and they do not get scaled. So the ctk widgets are nicely scaled and the tk widgets are not.
Do you, or the community, know of a way to align the behaviour so that both type of widgets get scaled when the app is dragged to a different monitor with different scaling?
Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions