6 Commits

8 changed files with 79 additions and 33 deletions

View File

@ -1,4 +1,4 @@
__version__ = "4.5.5" __version__ = "4.5.7"
import os import os
import sys import sys

View File

@ -252,6 +252,10 @@ class CTkButton(CTkBaseClass):
self.image = kwargs.pop("image") self.image = kwargs.pop("image")
require_redraw = True require_redraw = True
if "corner_radius" in kwargs:
self.corner_radius = kwargs.pop("corner_radius")
require_redraw = True
if "compound" in kwargs: if "compound" in kwargs:
self.compound = kwargs.pop("compound") self.compound = kwargs.pop("compound")
require_redraw = True require_redraw = True

View File

@ -104,13 +104,13 @@ class CTkSwitch(CTkBaseClass):
self.text_label.bind("<Leave>", self.on_leave) self.text_label.bind("<Leave>", self.on_leave)
self.text_label.bind("<Button-1>", self.toggle) self.text_label.bind("<Button-1>", self.toggle)
self.draw() # initial draw
self.set_cursor()
if self.variable is not None and self.variable != "": if self.variable is not None and self.variable != "":
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback) self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
self.check_state = True if self.variable.get() == self.onvalue else False self.check_state = True if self.variable.get() == self.onvalue else False
self.draw() # initial draw
self.set_cursor()
def set_scaling(self, *args, **kwargs): def set_scaling(self, *args, **kwargs):
super().set_scaling(*args, **kwargs) super().set_scaling(*args, **kwargs)
@ -209,14 +209,14 @@ class CTkSwitch(CTkBaseClass):
self.draw(no_color_updates=True) self.draw(no_color_updates=True)
if self.command is not None:
self.command()
if self.variable is not None: if self.variable is not None:
self.variable_callback_blocked = True self.variable_callback_blocked = True
self.variable.set(self.onvalue if self.check_state is True else self.offvalue) self.variable.set(self.onvalue if self.check_state is True else self.offvalue)
self.variable_callback_blocked = False self.variable_callback_blocked = False
if self.command is not None:
self.command()
def select(self, from_variable_callback=False): def select(self, from_variable_callback=False):
if self.state is not tkinter.DISABLED or from_variable_callback: if self.state is not tkinter.DISABLED or from_variable_callback:
self.check_state = True self.check_state = True

View File

@ -129,16 +129,42 @@ class CTk(tkinter.Tk):
if self.current_height > height: self.current_height = height if self.current_height > height: self.current_height = height
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height)) super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
def geometry(self, geometry_string): def geometry(self, geometry_string: str = None):
super().geometry(self.apply_geometry_scaling(geometry_string)) if geometry_string is not None:
super().geometry(self.apply_geometry_scaling(geometry_string))
# update width and height attributes # update width and height attributes
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers numbers = list(map(int, re.split(r"[x+-]", geometry_string))) # split geometry string into list of numbers
self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max
self.current_height = max(self.min_height, min(numbers[1], self.max_height)) self.current_height = max(self.min_height, min(numbers[1], self.max_height))
else:
return self.reverse_geometry_scaling(super().geometry())
def apply_geometry_scaling(self, geometry_string): def apply_geometry_scaling(self, geometry_string):
return re.sub(re.compile("\d+"), lambda match_obj: str(round(int(match_obj.group(0)) * self.window_scaling)), geometry_string) value_list = re.split(r"[x+-]", geometry_string)
separator_list = re.split(r"\d+", geometry_string)
if len(value_list) == 2:
scaled_width = str(round(int(value_list[0]) * self.window_scaling))
scaled_height = str(round(int(value_list[1]) * self.window_scaling))
return f"{scaled_width}x{scaled_height}"
elif len(value_list) == 4:
scaled_width = str(round(int(value_list[0]) * self.window_scaling))
scaled_height = str(round(int(value_list[1]) * self.window_scaling))
return f"{scaled_width}x{scaled_height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
def reverse_geometry_scaling(self, scaled_geometry_string):
value_list = re.split(r"[x+-]", scaled_geometry_string)
separator_list = re.split(r"\d+", scaled_geometry_string)
if len(value_list) == 2:
width = str(round(int(value_list[0]) / self.window_scaling))
height = str(round(int(value_list[1]) / self.window_scaling))
return f"{width}x{height}"
elif len(value_list) == 4:
width = str(round(int(value_list[0]) / self.window_scaling))
height = str(round(int(value_list[1]) / self.window_scaling))
return f"{width}x{height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
def apply_window_scaling(self, value): def apply_window_scaling(self, value):
if isinstance(value, (int, float)): if isinstance(value, (int, float)):

View File

@ -84,18 +84,30 @@ class CTkToplevel(tkinter.Toplevel):
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height)) super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
def apply_geometry_scaling(self, geometry_string): def apply_geometry_scaling(self, geometry_string):
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers value_list = re.split(r"[x+-]", geometry_string)
separator_list = re.split(r"\d+", geometry_string)
if len(numbers) == 2: if len(value_list) == 2:
return f"{self.apply_window_scaling(numbers[0]):.0f}x" +\ scaled_width = str(round(int(value_list[0]) * self.window_scaling))
f"{self.apply_window_scaling(numbers[1]):.0f}" scaled_height = str(round(int(value_list[1]) * self.window_scaling))
elif len(numbers) == 4: return f"{scaled_width}x{scaled_height}"
return f"{self.apply_window_scaling(numbers[0]):.0f}x" +\ elif len(value_list) == 4:
f"{self.apply_window_scaling(numbers[1]):.0f}+" +\ scaled_width = str(round(int(value_list[0]) * self.window_scaling))
f"{self.apply_window_scaling(numbers[2]):.0f}+" +\ scaled_height = str(round(int(value_list[1]) * self.window_scaling))
f"{self.apply_window_scaling(numbers[3]):.0f}" return f"{scaled_width}x{scaled_height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
else:
return geometry_string def reverse_geometry_scaling(self, scaled_geometry_string):
value_list = re.split(r"[x+-]", scaled_geometry_string)
separator_list = re.split(r"\d+", scaled_geometry_string)
if len(value_list) == 2:
width = str(round(int(value_list[0]) / self.window_scaling))
height = str(round(int(value_list[1]) / self.window_scaling))
return f"{width}x{height}"
elif len(value_list) == 4:
width = str(round(int(value_list[0]) / self.window_scaling))
height = str(round(int(value_list[1]) / self.window_scaling))
return f"{width}x{height}{separator_list[1]}{value_list[2]}{separator_list[2]}{value_list[3]}"
def apply_window_scaling(self, value): def apply_window_scaling(self, value):
if isinstance(value, (int, float)): if isinstance(value, (int, float)):
@ -103,13 +115,16 @@ class CTkToplevel(tkinter.Toplevel):
else: else:
return value return value
def geometry(self, geometry_string): def geometry(self, geometry_string: str = None):
super().geometry(self.apply_geometry_scaling(geometry_string)) if geometry_string is not None:
super().geometry(self.apply_geometry_scaling(geometry_string))
# update width and height attributes # update width and height attributes
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers
self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max self.current_width = max(self.min_width, min(numbers[0], self.max_width)) # bound value between min and max
self.current_height = max(self.min_height, min(numbers[1], self.max_height)) self.current_height = max(self.min_height, min(numbers[1], self.max_height))
else:
return self.reverse_geometry_scaling(super().geometry())
def destroy(self): def destroy(self):
AppearanceModeTracker.remove(self.set_appearance_mode) AppearanceModeTracker.remove(self.set_appearance_mode)

View File

@ -90,6 +90,7 @@ class App(customtkinter.CTk):
"amet consetetur sadipscing elitr,\n" + "amet consetetur sadipscing elitr,\n" +
"sed diam nonumy eirmod tempor" , "sed diam nonumy eirmod tempor" ,
height=100, height=100,
corner_radius=6, # <- custom corner radius
fg_color=("white", "gray38"), # <- custom tuple-color fg_color=("white", "gray38"), # <- custom tuple-color
justify=tkinter.LEFT) justify=tkinter.LEFT)
self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15) self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15)

View File

@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
github_url = "https://github.com/TomSchimansky/CustomTkinter" github_url = "https://github.com/TomSchimansky/CustomTkinter"
[tool.tbump.version] [tool.tbump.version]
current = "4.5.5" current = "4.5.7"
# Example of a semver regexp. # Example of a semver regexp.
# Make sure this matches current_version before # Make sure this matches current_version before

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = customtkinter name = customtkinter
version = 4.5.5 version = 4.5.7
description = Create modern looking GUIs with Python description = Create modern looking GUIs with Python
long_description = CustomTkinter UI-Library\n\n[](https://github.com/TomSchimansky/CustomTkinter/blob/master/documentation_images/Windows_dark.png)\n\nMore Information: https://github.com/TomSchimansky/CustomTkinter long_description = CustomTkinter UI-Library\n\n[](https://github.com/TomSchimansky/CustomTkinter/blob/master/documentation_images/Windows_dark.png)\n\nMore Information: https://github.com/TomSchimansky/CustomTkinter
long_description_content_type = text/markdown long_description_content_type = text/markdown