added no_color_updates option for set_scaling methods, added transparency effect on Windows when window scaling, changed scaling loop times

This commit is contained in:
TomSchimansky
2022-10-15 01:02:54 +02:00
parent 205cdae5f9
commit 9ffe61dd54
18 changed files with 70 additions and 57 deletions

View File

@@ -106,15 +106,11 @@ class CTkButton(CTkBaseClass):
super()._set_scaling(*args, **kwargs)
if self._text_label is not None:
self._text_label.destroy()
self._text_label = None
if self._image_label is not None:
self._image_label.destroy()
self._image_label = None
self._text_label.configure(font=self._apply_font_scaling(self._font))
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width: int = None, height: int = None):
super()._set_dimensions(width, height)

View File

@@ -137,7 +137,7 @@ class CTkCheckBox(CTkBaseClass):
height=self._apply_widget_scaling(self._desired_height))
self._canvas.configure(width=self._apply_widget_scaling(self._checkbox_width),
height=self._apply_widget_scaling(self._checkbox_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width: int = None, height: int = None):
super()._set_dimensions(width, height)

View File

@@ -135,7 +135,7 @@ class CTkComboBox(CTkBaseClass):
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width: int = None, height: int = None):
super()._set_dimensions(width, height)

View File

@@ -115,7 +115,7 @@ class CTkEntry(CTkBaseClass):
padx=self._apply_widget_scaling(self._corner_radius) if self._corner_radius >= 6 else self._apply_widget_scaling(6))
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width), height=self._apply_widget_scaling(self._desired_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width=None, height=None):
super()._set_dimensions(width, height)

View File

@@ -62,7 +62,7 @@ class CTkFrame(CTkBaseClass):
self._draw_engine = DrawEngine(self._canvas)
self._overwrite_preferred_drawing_method = overwrite_preferred_drawing_method
self._draw()
self._draw(no_color_updates=True)
def winfo_children(self) -> List[any]:
"""

View File

@@ -88,7 +88,7 @@ class CTkLabel(CTkBaseClass):
self._text_label.grid(row=0, column=0, sticky=text_label_grid_sticky,
padx=self._apply_widget_scaling(min(self._corner_radius, round(self._current_height/2))))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width=None, height=None):
super()._set_dimensions(width, height)

View File

@@ -148,7 +148,7 @@ class CTkOptionMenu(CTkBaseClass):
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width: int = None, height: int = None):
super()._set_dimensions(width, height)

View File

@@ -94,7 +94,7 @@ class CTkProgressBar(CTkBaseClass):
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width=None, height=None):
super()._set_dimensions(width, height)

View File

@@ -132,7 +132,7 @@ class CTkRadioButton(CTkBaseClass):
height=self._apply_widget_scaling(self._desired_height))
self._canvas.configure(width=self._apply_widget_scaling(self._radiobutton_width),
height=self._apply_widget_scaling(self._radiobutton_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width: int = None, height: int = None):
super()._set_dimensions(width, height)

View File

@@ -114,7 +114,7 @@ class CTkSlider(CTkBaseClass):
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width=None, height=None):
super()._set_dimensions(width, height)

View File

@@ -137,7 +137,7 @@ class CTkSwitch(CTkBaseClass):
height=self._apply_widget_scaling(self._desired_height))
self._canvas.configure(width=self._apply_widget_scaling(self._switch_width),
height=self._apply_widget_scaling(self._switch_height))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width: int = None, height: int = None):
super()._set_dimensions(width, height)

View File

@@ -123,7 +123,7 @@ class CTkTabview(CTkBaseClass):
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height - self._top_spacing - self._top_button_overhang))
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width=None, height=None):
super()._set_dimensions(width, height)

View File

@@ -182,7 +182,7 @@ class CTkTextbox(CTkBaseClass):
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))
self._create_grid_for_text_and_scrollbars(re_grid_textbox=False, re_grid_x_scrollbar=True, re_grid_y_scrollbar=True)
self._draw()
self._draw(no_color_updates=True)
def _set_dimensions(self, width=None, height=None):
super()._set_dimensions(width, height)

View File

@@ -48,32 +48,31 @@ class DropdownMenu(tkinter.Menu):
""" apply platform specific appearance attributes, configure all colors """
if sys.platform == "darwin":
self.configure(tearoff=False,
font=self._apply_font_scaling(self._font))
super().configure(tearoff=False,
font=self._apply_font_scaling(self._font))
elif sys.platform.startswith("win"):
print("dropdon win")
self.configure(tearoff=False,
relief="flat",
activebackground=ThemeManager.single_color(self._hover_color, self._appearance_mode),
borderwidth=0,
activeborderwidth=self._apply_widget_scaling(4),
bg=ThemeManager.single_color(self._fg_color, self._appearance_mode),
fg=ThemeManager.single_color(self._text_color, self._appearance_mode),
activeforeground=ThemeManager.single_color(self._text_color, self._appearance_mode),
font=self._apply_font_scaling(self._font),
cursor="hand2")
super().configure(tearoff=False,
relief="flat",
activebackground=ThemeManager.single_color(self._hover_color, self._appearance_mode),
borderwidth=self._apply_widget_scaling(4),
activeborderwidth=self._apply_widget_scaling(4),
bg=ThemeManager.single_color(self._fg_color, self._appearance_mode),
fg=ThemeManager.single_color(self._text_color, self._appearance_mode),
activeforeground=ThemeManager.single_color(self._text_color, self._appearance_mode),
font=self._apply_font_scaling(self._font),
cursor="hand2")
else:
self.configure(tearoff=False,
relief="flat",
activebackground=ThemeManager.single_color(self._hover_color, self._appearance_mode),
borderwidth=0,
activeborderwidth=0,
bg=ThemeManager.single_color(self._fg_color, self._appearance_mode),
fg=ThemeManager.single_color(self._text_color, self._appearance_mode),
activeforeground=ThemeManager.single_color(self._text_color, self._appearance_mode),
font=self._apply_font_scaling(self._font))
super().configure(tearoff=False,
relief="flat",
activebackground=ThemeManager.single_color(self._hover_color, self._appearance_mode),
borderwidth=0,
activeborderwidth=0,
bg=ThemeManager.single_color(self._fg_color, self._appearance_mode),
fg=ThemeManager.single_color(self._text_color, self._appearance_mode),
activeforeground=ThemeManager.single_color(self._text_color, self._appearance_mode),
font=self._apply_font_scaling(self._font))
def _add_menu_commands(self):
""" delete existing menu labels and createe new labels with command according to values list """
@@ -110,15 +109,15 @@ class DropdownMenu(tkinter.Menu):
def configure(self, **kwargs):
if "fg_color" in kwargs:
self._fg_color = kwargs.pop("fg_color")
self.configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
super().configure(bg=ThemeManager.single_color(self._fg_color, self._appearance_mode))
if "hover_color" in kwargs:
self._hover_color = kwargs.pop("hover_color")
self.configure(activebackground=ThemeManager.single_color(self._hover_color, self._appearance_mode))
super().configure(activebackground=ThemeManager.single_color(self._hover_color, self._appearance_mode))
if "text_color" in kwargs:
self._text_color = kwargs.pop("text_color")
self.configure(fg=ThemeManager.single_color(self._text_color, self._appearance_mode))
super().configure(fg=ThemeManager.single_color(self._text_color, self._appearance_mode))
if "font" in kwargs:
self._font = kwargs.pop("font")
@@ -151,6 +150,9 @@ class DropdownMenu(tkinter.Menu):
elif attribute_name == "values":
return self._values
else:
return super().cget(attribute_name)
def _apply_widget_scaling(self, value: Union[int, float, str]) -> Union[float, str]:
if isinstance(value, (int, float)):
return value * self._widget_scaling
@@ -183,10 +185,7 @@ class DropdownMenu(tkinter.Menu):
self._widget_scaling = new_widget_scaling
self._spacing_scaling = new_spacing_scaling
super().configure(font=self._apply_font_scaling(self._font))
if sys.platform.startswith("win"):
self.configure(activeborderwidth=self._apply_widget_scaling(4))
self._configure_menu_for_platforms()
def _set_appearance_mode(self, mode_string):
""" colors won't update on appearance mode change when dropdown is open, because it's not necessary """