3 Commits

6 changed files with 69 additions and 27 deletions

View File

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

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.6" 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.6 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