mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
small fixes in CTkToplevel and CTkInputDialog
This commit is contained in:
@ -27,6 +27,7 @@ class CTkInputDialog:
|
||||
|
||||
self.height = len(text.split("\n"))*20 + 150
|
||||
|
||||
self.text = text
|
||||
self.window_bg_color = ThemeManager.theme["color"]["window_bg_color"]
|
||||
self.fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
||||
self.hover_color = ThemeManager.theme["color"]["button_hover"] if hover_color == "default_theme" else hover_color
|
||||
@ -34,12 +35,16 @@ class CTkInputDialog:
|
||||
|
||||
self.top = CTkToplevel()
|
||||
self.top.geometry(f"{280}x{self.height}")
|
||||
self.top.resizable(False, False)
|
||||
self.top.minsize(280, self.height)
|
||||
self.top.maxsize(280, self.height)
|
||||
self.top.title(title)
|
||||
self.top.lift()
|
||||
self.top.focus_force()
|
||||
self.top.grab_set()
|
||||
|
||||
self.top.after(10, self.create_widgets) # create widgets with slight delay, to avoid white flickering of background
|
||||
|
||||
def create_widgets(self):
|
||||
self.label_frame = CTkFrame(master=self.top,
|
||||
corner_radius=0,
|
||||
fg_color=self.window_bg_color,
|
||||
@ -55,7 +60,7 @@ class CTkInputDialog:
|
||||
self.button_and_entry_frame.place(relx=0.5, rely=1, anchor=tkinter.S)
|
||||
|
||||
self.myLabel = CTkLabel(master=self.label_frame,
|
||||
text=text,
|
||||
text=self.text,
|
||||
width=300,
|
||||
fg_color=None,
|
||||
height=self.height-100)
|
||||
|
@ -26,8 +26,8 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
ScalingTracker.add_widget(self.set_scaling, self)
|
||||
self.window_scaling = ScalingTracker.get_window_scaling(self)
|
||||
|
||||
self.current_width = 600 # initial window size, always without scaling
|
||||
self.current_height = 500
|
||||
self.current_width = 200 # initial window size, always without scaling
|
||||
self.current_height = 200
|
||||
self.min_width: int = 0
|
||||
self.min_height: int = 0
|
||||
self.max_width: int = 1_000_000
|
||||
@ -47,6 +47,7 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
AppearanceModeTracker.add(self.set_appearance_mode, self)
|
||||
super().configure(bg=ThemeManager.single_color(self.fg_color, self.appearance_mode))
|
||||
super().title("CTkToplevel")
|
||||
# self.geometry(f"{self.current_width}x{self.current_height}")
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
if self.appearance_mode == 1:
|
||||
@ -54,6 +55,8 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
else:
|
||||
self.windows_set_titlebar_color("light")
|
||||
|
||||
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()
|
||||
@ -65,20 +68,17 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
|
||||
self.window_scaling = new_window_scaling
|
||||
|
||||
# reset min, max and resizable constraints for applying scaling
|
||||
if self.last_resizable_args is not None:
|
||||
super().resizable(True, True)
|
||||
if self.min_width is not None or self.min_height is not None:
|
||||
super().minsize(0, 0)
|
||||
if self.max_width is not None or self.max_height is not None:
|
||||
super().maxsize(1_000_000, 1_000_000)
|
||||
# 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))
|
||||
super().geometry(
|
||||
f"{self.apply_window_scaling(self.current_width)}x" + f"{self.apply_window_scaling(self.current_height)}")
|
||||
print("set_scaling:", self.apply_window_scaling(self.current_width), self.max_width, self.min_width)
|
||||
|
||||
# set new window size by applying scaling to the current window size
|
||||
self.geometry(f"{self.current_width}x{self.current_height}")
|
||||
# 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)
|
||||
|
||||
# set scaled min, max sizes and reapply resizable
|
||||
if self.last_resizable_args is not None:
|
||||
super().resizable(*self.last_resizable_args[0], **self.last_resizable_args[1]) # args, kwargs
|
||||
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))
|
||||
if self.max_width is not None or self.max_height is not None:
|
||||
|
Reference in New Issue
Block a user