mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
CTk scaling fixes for Windows
This commit is contained in:
parent
ec8cecb575
commit
9bdf2436f5
@ -20,7 +20,7 @@
|
||||
"progressbar_progress": ["#3B8ED0", "#1F6AA5"],
|
||||
"progressbar_border": ["gray", "gray"],
|
||||
"slider": ["#939BA2", "#4A4D50"],
|
||||
"slider_progress": ["white", "#AAB0B5"],
|
||||
"slider_progress": ["gray40", "#AAB0B5"],
|
||||
"slider_button": ["#3B8ED0", "#1F6AA5"],
|
||||
"slider_button_hover": ["#36719F", "#144870"],
|
||||
"switch": ["#939BA2", "#4A4D50"],
|
||||
|
@ -20,7 +20,7 @@ class CTkCanvas(tkinter.Canvas):
|
||||
|
||||
radius_to_char_fine_windows_10 = {19: 'A', 18: 'A', 17: 'B', 16: 'B', 15: 'B', 14: 'B', 13: 'C', 12: 'C',
|
||||
11: 'C', 10: 'C',
|
||||
9: 'D', 8: 'D', 7: 'D', 6: 'F', 5: 'D', 4: 'G', 3: 'G', 2: 'H', 1: 'H',
|
||||
9: 'D', 8: 'D', 7: 'D', 6: 'C', 5: 'D', 4: 'G', 3: 'G', 2: 'H', 1: 'H',
|
||||
0: 'A'}
|
||||
|
||||
radius_to_char_fine_windows_11 = {19: 'A', 18: 'A', 17: 'B', 16: 'B', 15: 'B', 14: 'B', 13: 'C', 12: 'C',
|
||||
|
@ -57,6 +57,7 @@ class CTkTextbox(CTkBaseClass):
|
||||
height=0,
|
||||
font=self.text_font,
|
||||
highlightthickness=0,
|
||||
relief="flat",
|
||||
insertbackground=ThemeManager.single_color(("black", "white"), self._appearance_mode),
|
||||
bg=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||
**kwargs)
|
||||
|
@ -62,17 +62,23 @@ class CTk(tkinter.Tk):
|
||||
|
||||
self.bind('<Configure>', self.update_dimensions_event)
|
||||
|
||||
def update_dimensions_event(self, event=None):
|
||||
detected_width = self.winfo_width() # detect current window size
|
||||
detected_height = self.winfo_height()
|
||||
self.block_update_dimensions_event = False
|
||||
|
||||
if self.current_width != round(detected_width / self.window_scaling) or self.current_height != round(detected_height / self.window_scaling):
|
||||
self.current_width = round(detected_width / self.window_scaling) # adjust current size according to new size given by event
|
||||
self.current_height = round(detected_height / self.window_scaling) # _current_width and _current_height are independent of the scale
|
||||
def update_dimensions_event(self, event=None):
|
||||
if not self.block_update_dimensions_event:
|
||||
detected_width = self.winfo_width() # detect current window size
|
||||
detected_height = self.winfo_height()
|
||||
|
||||
if self.current_width != round(detected_width / self.window_scaling) or self.current_height != round(detected_height / self.window_scaling):
|
||||
self.current_width = round(detected_width / self.window_scaling) # adjust current size according to new size given by event
|
||||
self.current_height = round(detected_height / self.window_scaling) # _current_width and _current_height are independent of the scale
|
||||
|
||||
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
|
||||
self.window_scaling = new_window_scaling
|
||||
|
||||
# block update_dimensions_event to prevent current_width and current_height to get updated
|
||||
self.block_update_dimensions_event = True
|
||||
|
||||
# force new dimensions on window by using min, max, and geometry
|
||||
super().minsize(self.apply_window_scaling(self.current_width), self.apply_window_scaling(self.current_height))
|
||||
super().maxsize(self.apply_window_scaling(self.current_width), self.apply_window_scaling(self.current_height))
|
||||
@ -81,6 +87,11 @@ class CTk(tkinter.Tk):
|
||||
# set new scaled min and max with 400ms delay (otherwise it won't work for some reason)
|
||||
self.after(400, self.set_scaled_min_max)
|
||||
|
||||
# release the blocking of update_dimensions_event after a small amount of time (slight delay is necessary)
|
||||
def set_block_update_dimensions_event_false():
|
||||
self.block_update_dimensions_event = False
|
||||
self.after(100, lambda: set_block_update_dimensions_event_false())
|
||||
|
||||
def set_scaled_min_max(self):
|
||||
if self.min_width is not None or self.min_height is not None:
|
||||
super().minsize(self.apply_window_scaling(self.min_width), self.apply_window_scaling(self.min_height))
|
||||
@ -131,6 +142,7 @@ class CTk(tkinter.Tk):
|
||||
|
||||
def geometry(self, geometry_string: str = None):
|
||||
if geometry_string is not None:
|
||||
print(self.apply_geometry_scaling(geometry_string), geometry_string)
|
||||
super().geometry(self.apply_geometry_scaling(geometry_string))
|
||||
|
||||
# update width and height attributes
|
||||
|
@ -27,21 +27,21 @@ f4 = customtkinter.CTkFrame(app, fg_color="gray90", corner_radius=0)
|
||||
f4.grid(row=0, column=3, rowspan=1, columnspan=1, sticky="nsew")
|
||||
f4.grid_columnconfigure(0, weight=1)
|
||||
|
||||
for i in range(0, 21, 1):
|
||||
b = customtkinter.CTkButton(f1, corner_radius=i, height=34, border_width=2, text=f"{i} {i-2}",
|
||||
for i in range(0, 16, 1):
|
||||
b = customtkinter.CTkButton(f1, corner_radius=i, height=30, border_width=1, text=f"{i} {i-1}",
|
||||
border_color="white", fg_color=None, text_color="white")
|
||||
# b = tkinter.Button(f1, text=f"{i} {i-2}", width=20)
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
b = customtkinter.CTkButton(f2, corner_radius=i, height=34, border_width=0, text=f"{i}",
|
||||
b = customtkinter.CTkButton(f2, corner_radius=i, height=30, border_width=0, text=f"{i}",
|
||||
fg_color="#228da8")
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
b = customtkinter.CTkButton(f3, corner_radius=i, height=34, border_width=2, text=f"{i} {i-2}",
|
||||
b = customtkinter.CTkButton(f3, corner_radius=i, height=30, border_width=1, text=f"{i} {i-1}",
|
||||
fg_color=None, border_color="gray20", text_color="black")
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
b = customtkinter.CTkButton(f4, corner_radius=i, height=34, border_width=0, text=f"{i}",
|
||||
b = customtkinter.CTkButton(f4, corner_radius=i, height=30, border_width=0, text=f"{i}",
|
||||
border_color="gray10", fg_color="#228da8")
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user