mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
39f369a8d4 | |||
423d0886c9 | |||
d2f8fd012f | |||
dcde8d69d8 | |||
81f3f9a622 | |||
65c45abe32 | |||
64c8b8345d | |||
9a144bfc6b | |||
d9db3b64af | |||
2db46afaf0 | |||
8c9183006c | |||
f39ee5764a | |||
69216469a4 | |||
d890d243a5 | |||
deebaa9163 | |||
5a4c28b178 | |||
73ab410a96 | |||
9bdf2436f5 | |||
91efc0ffc1 | |||
99550ab7fd | |||
46b20d6605 | |||
013e186ca6 | |||
6df8a1f44a | |||
4516a5edb1 | |||
bd19d2f3e6 | |||
ec8cecb575 |
@ -1,4 +1,4 @@
|
||||
__version__ = "4.5.10"
|
||||
__version__ = "4.5.11"
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
@ -45,7 +45,7 @@ class AppearanceModeTracker:
|
||||
cls.app_list.append(app)
|
||||
|
||||
if not cls.update_loop_running:
|
||||
app.after(500, cls.update)
|
||||
app.after(cls.update_loop_interval, cls.update)
|
||||
cls.update_loop_running = True
|
||||
|
||||
@classmethod
|
||||
|
@ -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"],
|
||||
|
@ -1,41 +1,41 @@
|
||||
{
|
||||
"color": {
|
||||
"window_bg_color": ["#181b28", "#181b28"],
|
||||
"button": ["#212435", "#212435"],
|
||||
"button_hover": ["#171926", "#171926"],
|
||||
"button_border": ["#080b12", "#080b12"],
|
||||
"window_bg_color": ["#ebf0f5", "#181b28"],
|
||||
"button": ["#e46bff", "#212435"],
|
||||
"button_hover": ["#8593d6", "#171926"],
|
||||
"button_border": ["#525983", "#080b12"],
|
||||
"checkbox_border": ["#01e9c4", "#01e9c4"],
|
||||
"checkmark": ["#01e9c4", "#01e9c4"],
|
||||
"entry": ["#212435", "#212435"],
|
||||
"entry_border": ["#080b12", "#080b12"],
|
||||
"entry": ["#dee2e7", "#212435"],
|
||||
"entry_border": ["#fa00d0", "#080b12"],
|
||||
"entry_placeholder_text": ["#cdc8ce", "#cdc8ce"],
|
||||
"frame_border": ["#10121f", "#10121f"],
|
||||
"frame_low": ["#181b28", "#181b28"],
|
||||
"frame_high": ["#181b28", "#181b28"],
|
||||
"frame_border": ["#525983", "#10121f"],
|
||||
"frame_low": ["#dee2e7", "#181b28"],
|
||||
"frame_high": ["#dee2e7", "#1b1e2d"],
|
||||
"label": [null, null],
|
||||
"text": ["#cdc8ce", "#cdc8ce"],
|
||||
"text_disabled": ["#7a8894", "#7a8894"],
|
||||
"text": ["#0c0e14", "#cdc8ce"],
|
||||
"text_disabled": ["#5e6062", "#7a8894"],
|
||||
"text_button_disabled": ["#7a8894", "#7a8894"],
|
||||
"progressbar": ["#c452f8", "#c452f8"],
|
||||
"progressbar": ["#fa00d0", "#fa00d0"],
|
||||
"progressbar_progress": ["#363844", "#363844"],
|
||||
"progressbar_border": ["#0d101f", "#0d101f"],
|
||||
"slider": ["#c452f8", "#c452f8"],
|
||||
"slider_progress": ["#363844", "#363844"],
|
||||
"slider_button": ["#5b40c5", "#5b40c5"],
|
||||
"slider_button_hover": ["#c452f8", "#c452f8"],
|
||||
"switch": ["#1f2233", "#1f2233"],
|
||||
"progressbar_border": ["#fa00d0", "#0d101f"],
|
||||
"slider": ["#fa00d0", "#fa00d0"],
|
||||
"slider_progress": ["#0d101f", "#0d101f"],
|
||||
"slider_button": ["#fa00d0", "#fa00d0"],
|
||||
"slider_button_hover": ["#e46bff", "#fa00d0"],
|
||||
"switch": ["#7681be", "#1f2233"],
|
||||
"switch_progress": ["#00e6c3", "#00e6c3"],
|
||||
"switch_button": ["#2e324a", "#2e324a"],
|
||||
"switch_button_hover": ["#2e324a", "#2e324a"],
|
||||
"optionmenu_button": ["#36719F", "#144870"],
|
||||
"optionmenu_button_hover": ["#27577D", "#203A4F"],
|
||||
"combobox_border": ["#979DA2", "#565B5E"],
|
||||
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
||||
"dropdown_color": ["gray90", "gray20"],
|
||||
"dropdown_hover": ["gray75", "gray28"],
|
||||
"dropdown_text": ["gray10", "#DCE4EE"],
|
||||
"scrollbar_button": ["gray55", "gray41"],
|
||||
"scrollbar_button_hover": ["gray40", "gray53"]
|
||||
"switch_button": ["#525983", "#2e324a"],
|
||||
"switch_button_hover": ["#fa00d0", "#2e324a"],
|
||||
"optionmenu_button": ["#525983", "#080b12"],
|
||||
"optionmenu_button_hover": ["#fa00d0", "#080b12"],
|
||||
"combobox_border": ["#525983", "#080b12"],
|
||||
"combobox_button_hover": ["#fa00d0", "#fa00d0"],
|
||||
"dropdown_color": ["#dee2e7", "#212435"],
|
||||
"dropdown_hover": ["#fa00d0", "#fa00d0"],
|
||||
"dropdown_text": ["#0c0e14", "#cdc8ce"],
|
||||
"scrollbar_button": ["#fa00d0", "#fa00d0"],
|
||||
"scrollbar_button_hover": ["#9b45ff", "#9b45ff"]
|
||||
},
|
||||
"text": {
|
||||
"macOS": {
|
||||
@ -53,16 +53,16 @@
|
||||
},
|
||||
"shape": {
|
||||
"button_corner_radius": 8,
|
||||
"button_border_width": 2,
|
||||
"button_border_width": 1,
|
||||
"checkbox_corner_radius": 7,
|
||||
"checkbox_border_width": 3,
|
||||
"checkbox_border_width": 1,
|
||||
"radiobutton_corner_radius": 1000,
|
||||
"radiobutton_border_width_unchecked": 3,
|
||||
"radiobutton_border_width_unchecked": 2,
|
||||
"radiobutton_border_width_checked": 6,
|
||||
"entry_border_width": 2,
|
||||
"entry_border_width": 1,
|
||||
"frame_corner_radius": 10,
|
||||
"frame_border_width": 2,
|
||||
"label_corner_radius": 0,
|
||||
"frame_border_width": 1,
|
||||
"label_corner_radius": 3,
|
||||
"progressbar_border_width": 2,
|
||||
"progressbar_corner_radius": 1000,
|
||||
"slider_border_width": 6,
|
||||
|
@ -6,13 +6,15 @@ from typing import Union
|
||||
|
||||
class FontManager:
|
||||
|
||||
linux_font_path = "~/.local/share/fonts/"
|
||||
|
||||
@classmethod
|
||||
def init_font_manager(cls):
|
||||
# Linux
|
||||
if sys.platform.startswith("linux"):
|
||||
try:
|
||||
if not os.path.isdir(os.path.expanduser('~/.fonts/')):
|
||||
os.mkdir(os.path.expanduser('~/.fonts/'))
|
||||
if not os.path.isdir(os.path.expanduser(cls.linux_font_path)):
|
||||
os.mkdir(os.path.expanduser(cls.linux_font_path))
|
||||
return True
|
||||
except Exception as err:
|
||||
sys.stderr.write("FontManager error: " + str(err) + "\n")
|
||||
@ -53,7 +55,7 @@ class FontManager:
|
||||
# Linux
|
||||
elif sys.platform.startswith("linux"):
|
||||
try:
|
||||
shutil.copy(font_path, os.path.expanduser("~/.fonts/"))
|
||||
shutil.copy(font_path, os.path.expanduser(cls.linux_font_path))
|
||||
return True
|
||||
except Exception as err:
|
||||
sys.stderr.write("FontManager error: " + str(err) + "\n")
|
||||
|
@ -243,6 +243,11 @@ class CTkButton(CTkBaseClass):
|
||||
else:
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
@ -362,7 +367,7 @@ class CTkButton(CTkBaseClass):
|
||||
|
||||
def clicked(self, event=None):
|
||||
if self.command is not None:
|
||||
if self.state is not tkinter.DISABLED:
|
||||
if self.state != tkinter.DISABLED:
|
||||
|
||||
# click animation: change color with .on_leave() and back to normal after 100ms with click_animation()
|
||||
self.on_leave()
|
||||
|
@ -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',
|
||||
|
@ -177,6 +177,11 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -203,6 +203,10 @@ class CTkComboBox(CTkBaseClass):
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.entry.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "command" in kwargs:
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
|
@ -77,7 +77,7 @@ class CTkEntry(CTkBaseClass):
|
||||
self.entry.bind('<FocusOut>', self.entry_focus_out)
|
||||
self.entry.bind('<FocusIn>', self.entry_focus_in)
|
||||
|
||||
self.set_placeholder()
|
||||
self.activate_placeholder()
|
||||
self.draw()
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
@ -176,6 +176,8 @@ class CTkEntry(CTkBaseClass):
|
||||
if self.placeholder_text_active:
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.placeholder_text)
|
||||
else:
|
||||
self.activate_placeholder()
|
||||
|
||||
if "placeholder_text_color" in kwargs:
|
||||
self.placeholder_text_color = kwargs.pop("placeholder_text_color")
|
||||
@ -185,6 +187,10 @@ class CTkEntry(CTkBaseClass):
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
self.entry.configure(textvariable=self.textvariable)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.entry.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "show" in kwargs:
|
||||
if self.placeholder_text_active:
|
||||
self.pre_placeholder_arguments["show"] = kwargs.pop("show")
|
||||
@ -198,7 +204,7 @@ class CTkEntry(CTkBaseClass):
|
||||
|
||||
self.entry.configure(**kwargs) # pass remaining kwargs to entry
|
||||
|
||||
def set_placeholder(self):
|
||||
def activate_placeholder(self):
|
||||
if self.entry.get() == "" and self.placeholder_text is not None and (self.textvariable is None or self.textvariable == ""):
|
||||
self.placeholder_text_active = True
|
||||
|
||||
@ -207,7 +213,7 @@ class CTkEntry(CTkBaseClass):
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.placeholder_text)
|
||||
|
||||
def clear_placeholder(self):
|
||||
def deactivate_placeholder(self):
|
||||
if self.placeholder_text_active:
|
||||
self.placeholder_text_active = False
|
||||
|
||||
@ -217,19 +223,19 @@ class CTkEntry(CTkBaseClass):
|
||||
self.entry[argument] = value
|
||||
|
||||
def entry_focus_out(self, event=None):
|
||||
self.set_placeholder()
|
||||
self.activate_placeholder()
|
||||
|
||||
def entry_focus_in(self, event=None):
|
||||
self.clear_placeholder()
|
||||
self.deactivate_placeholder()
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.entry.delete(*args, **kwargs)
|
||||
|
||||
if self.entry.get() == "":
|
||||
self.set_placeholder()
|
||||
self.activate_placeholder()
|
||||
|
||||
def insert(self, *args, **kwargs):
|
||||
self.clear_placeholder()
|
||||
self.deactivate_placeholder()
|
||||
|
||||
return self.entry.insert(*args, **kwargs)
|
||||
|
||||
|
@ -123,6 +123,10 @@ class CTkLabel(CTkBaseClass):
|
||||
self.text_label.configure(text=self.text)
|
||||
del kwargs["text"]
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
require_redraw = True
|
||||
|
@ -210,6 +210,10 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "command" in kwargs:
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
@ -245,7 +249,8 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.dropdown_menu.configure(text_color=kwargs.pop("dropdown_text_color"))
|
||||
|
||||
if "dropdown_text_font" in kwargs:
|
||||
self.dropdown_menu.configure(text_font=kwargs.pop("dropdown_text_font"))
|
||||
self.dropdown_text_font = kwargs.pop("dropdown_text_font")
|
||||
self.dropdown_menu.configure(text_font=self.dropdown_text_font)
|
||||
|
||||
if "dynamic_resizing" in kwargs:
|
||||
self.dynamic_resizing = kwargs.pop("dynamic_resizing")
|
||||
|
@ -156,6 +156,10 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -272,6 +272,10 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
|
@ -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)
|
||||
@ -160,6 +161,13 @@ class CTkTextbox(CTkBaseClass):
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
if "text_font" in kwargs:
|
||||
self.text_font = kwargs.pop("text_font")
|
||||
self.textbox.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
if "font" in kwargs:
|
||||
raise ValueError("No attribute named font. Use text_font instead of font for CTk widgets")
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
super().configure(bg_color=kwargs.pop("bg_color"), require_redraw=require_redraw)
|
||||
else:
|
||||
|
@ -153,7 +153,7 @@ class CTkBaseClass(tkinter.Frame):
|
||||
|
||||
# if fg_color of master is None, try to retrieve fg_color from master of master
|
||||
elif hasattr(master_widget.master, "master"):
|
||||
return self.detect_color_of_master(self.master.master)
|
||||
return self.detect_color_of_master(master_widget.master)
|
||||
|
||||
elif isinstance(master_widget, (ttk.Frame, ttk.LabelFrame, ttk.Notebook, ttk.Label)): # master is ttk widget
|
||||
try:
|
||||
|
@ -42,6 +42,8 @@ class CTkInputDialog:
|
||||
self.top.focus_force()
|
||||
self.top.grab_set()
|
||||
|
||||
self.top.protocol("WM_DELETE_WINDOW", self.on_closing)
|
||||
|
||||
self.top.after(10, self.create_widgets) # create widgets with slight delay, to avoid white flickering of background
|
||||
|
||||
def create_widgets(self):
|
||||
@ -95,6 +97,9 @@ class CTkInputDialog:
|
||||
self.user_input = self.entry.get()
|
||||
self.running = False
|
||||
|
||||
def on_closing(self):
|
||||
self.running = False
|
||||
|
||||
def cancel_event(self):
|
||||
self.running = False
|
||||
|
||||
|
@ -52,7 +52,10 @@ class CTk(tkinter.Tk):
|
||||
super().title("CTk")
|
||||
self.geometry(f"{self.current_width}x{self.current_height}")
|
||||
|
||||
self.window_exists = False # indicates if the window is already shown through .update or .mainloop
|
||||
self.state_before_windows_set_titlebar_color = None
|
||||
self.window_exists = False # indicates if the window is already shown through update() or mainloop() after init
|
||||
self.withdraw_called_before_window_exists = False # indicates if withdraw() was called before window is first shown through update() or mainloop()
|
||||
self.iconify_called_before_window_exists = False # indicates if iconify() was called before window is first shown through update() or mainloop()
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
if self.appearance_mode == 1:
|
||||
@ -62,17 +65,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 +90,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))
|
||||
@ -93,16 +107,36 @@ class CTk(tkinter.Tk):
|
||||
self.disable_macos_dark_title_bar()
|
||||
super().destroy()
|
||||
|
||||
def withdraw(self):
|
||||
if self.window_exists is False:
|
||||
self.withdraw_called_before_window_exists = True
|
||||
super().withdraw()
|
||||
|
||||
def iconify(self):
|
||||
if self.window_exists is False:
|
||||
self.iconify_called_before_window_exists = True
|
||||
super().iconify()
|
||||
|
||||
def update(self):
|
||||
if self.window_exists is False:
|
||||
self.deiconify()
|
||||
self.window_exists = True
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
if not self.withdraw_called_before_window_exists and not self.iconify_called_before_window_exists:
|
||||
# print("window dont exists -> deiconify in update")
|
||||
self.deiconify()
|
||||
|
||||
super().update()
|
||||
|
||||
def mainloop(self, *args, **kwargs):
|
||||
if not self.window_exists:
|
||||
self.deiconify()
|
||||
self.window_exists = True
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
if not self.withdraw_called_before_window_exists and not self.iconify_called_before_window_exists:
|
||||
# print("window dont exists -> deiconify in mainloop")
|
||||
self.deiconify()
|
||||
|
||||
super().mainloop(*args, **kwargs)
|
||||
|
||||
def resizable(self, *args, **kwargs):
|
||||
@ -134,37 +168,49 @@ class CTk(tkinter.Tk):
|
||||
super().geometry(self.apply_geometry_scaling(geometry_string))
|
||||
|
||||
# update width and height attributes
|
||||
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_height = max(self.min_height, min(numbers[1], self.max_height))
|
||||
width, height, x, y = self.parse_geometry_string(geometry_string)
|
||||
if width is not None and height is not None:
|
||||
self.current_width = max(self.min_width, min(width, self.max_width)) # bound value between min and max
|
||||
self.current_height = max(self.min_height, min(height, self.max_height))
|
||||
else:
|
||||
return self.reverse_geometry_scaling(super().geometry())
|
||||
|
||||
def apply_geometry_scaling(self, geometry_string):
|
||||
value_list = re.split(r"[x+-]", geometry_string)
|
||||
separator_list = re.split(r"\d+", geometry_string)
|
||||
@staticmethod
|
||||
def parse_geometry_string(geometry_string: str) -> tuple:
|
||||
# index: 1 2 3 4 5 6
|
||||
# regex group structure: ('<width>x<height>', '<width>', '<height>', '+-<x>+-<y>', '-<x>', '-<y>')
|
||||
result = re.search(r"((\d+)x(\d+)){0,1}(\+{0,1}([+-]{0,1}\d+)\+{0,1}([+-]{0,1}\d+)){0,1}", 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[2]}{value_list[2]}{separator_list[3]}{value_list[3]}"
|
||||
width = int(result.group(2)) if result.group(2) is not None else None
|
||||
height = int(result.group(3)) if result.group(3) is not None else None
|
||||
x = int(result.group(5)) if result.group(5) is not None else None
|
||||
y = int(result.group(6)) if result.group(6) is not None else None
|
||||
|
||||
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)
|
||||
return width, height, x, y
|
||||
|
||||
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[2]}{value_list[2]}{separator_list[3]}{value_list[3]}"
|
||||
def apply_geometry_scaling(self, geometry_string: str) -> str:
|
||||
width, height, x, y = self.parse_geometry_string(geometry_string)
|
||||
|
||||
if x is None and y is None: # no <x> and <y> in geometry_string
|
||||
return f"{round(width * self.window_scaling)}x{round(height * self.window_scaling)}"
|
||||
|
||||
elif width is None and height is None: # no <width> and <height> in geometry_string
|
||||
return f"+{x}+{y}"
|
||||
|
||||
else:
|
||||
return f"{round(width * self.window_scaling)}x{round(height * self.window_scaling)}+{x}+{y}"
|
||||
|
||||
def reverse_geometry_scaling(self, scaled_geometry_string: str) -> str:
|
||||
width, height, x, y = self.parse_geometry_string(scaled_geometry_string)
|
||||
|
||||
if x is None and y is None: # no <x> and <y> in geometry_string
|
||||
return f"{round(width / self.window_scaling)}x{round(height / self.window_scaling)}"
|
||||
|
||||
elif width is None and height is None: # no <width> and <height> in geometry_string
|
||||
return f"+{x}+{y}"
|
||||
|
||||
else:
|
||||
return f"{round(width / self.window_scaling)}x{round(height / self.window_scaling)}+{x}+{y}"
|
||||
|
||||
def apply_window_scaling(self, value):
|
||||
if isinstance(value, (int, float)):
|
||||
@ -240,8 +286,15 @@ class CTk(tkinter.Tk):
|
||||
|
||||
if sys.platform.startswith("win") and not Settings.deactivate_windows_window_header_manipulation:
|
||||
|
||||
super().withdraw() # hide window so that it can be redrawn after the titlebar change so that the color change is visible
|
||||
if not self.window_exists:
|
||||
if self.window_exists:
|
||||
self.state_before_windows_set_titlebar_color = self.state()
|
||||
# print("window_exists -> state_before_windows_set_titlebar_color: ", self.state_before_windows_set_titlebar_color)
|
||||
|
||||
if self.state_before_windows_set_titlebar_color != "iconic" or self.state_before_windows_set_titlebar_color != "withdrawn":
|
||||
super().withdraw() # hide window so that it can be redrawn after the titlebar change so that the color change is visible
|
||||
else:
|
||||
# print("window dont exists -> withdraw and update")
|
||||
super().withdraw()
|
||||
super().update()
|
||||
|
||||
if color_mode.lower() == "dark":
|
||||
@ -270,7 +323,17 @@ class CTk(tkinter.Tk):
|
||||
print(err)
|
||||
|
||||
if self.window_exists:
|
||||
self.deiconify()
|
||||
# print("window_exists -> return to original state: ", self.state_before_windows_set_titlebar_color)
|
||||
if self.state_before_windows_set_titlebar_color == "normal":
|
||||
self.deiconify()
|
||||
elif self.state_before_windows_set_titlebar_color == "iconic":
|
||||
self.iconify()
|
||||
elif self.state_before_windows_set_titlebar_color == "zoomed":
|
||||
self.state("zoomed")
|
||||
else:
|
||||
self.state(self.state_before_windows_set_titlebar_color) # other states
|
||||
else:
|
||||
pass # wait for update or mainloop to be called
|
||||
|
||||
def set_appearance_mode(self, mode_string):
|
||||
if mode_string.lower() == "dark":
|
||||
|
@ -47,7 +47,11 @@ 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}")
|
||||
|
||||
self.state_before_windows_set_titlebar_color = None
|
||||
self.windows_set_titlebar_color_called = False # indicates if windows_set_titlebar_color was called, stays True until revert_withdraw_after_windows_set_titlebar_color is called
|
||||
self.withdraw_called_after_windows_set_titlebar_color = False # indicates if withdraw() was called after windows_set_titlebar_color
|
||||
self.iconify_called_after_windows_set_titlebar_color = False # indicates if iconify() was called after windows_set_titlebar_color
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
if self.appearance_mode == 1:
|
||||
@ -83,31 +87,54 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
if self.max_width is not None or self.max_height is not None:
|
||||
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
|
||||
|
||||
def apply_geometry_scaling(self, geometry_string):
|
||||
value_list = re.split(r"[x+-]", geometry_string)
|
||||
separator_list = re.split(r"\d+", geometry_string)
|
||||
def geometry(self, geometry_string: str = None):
|
||||
if geometry_string is not None:
|
||||
super().geometry(self.apply_geometry_scaling(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[2]}{value_list[2]}{separator_list[3]}{value_list[3]}"
|
||||
# update width and height attributes
|
||||
width, height, x, y = self.parse_geometry_string(geometry_string)
|
||||
if width is not None and height is not None:
|
||||
self.current_width = max(self.min_width, min(width, self.max_width)) # bound value between min and max
|
||||
self.current_height = max(self.min_height, min(height, self.max_height))
|
||||
else:
|
||||
return self.reverse_geometry_scaling(super().geometry())
|
||||
|
||||
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)
|
||||
@staticmethod
|
||||
def parse_geometry_string(geometry_string: str) -> tuple:
|
||||
# index: 1 2 3 4 5 6
|
||||
# regex group structure: ('<width>x<height>', '<width>', '<height>', '+-<x>+-<y>', '-<x>', '-<y>')
|
||||
result = re.search(r"((\d+)x(\d+)){0,1}(\+{0,1}([+-]{0,1}\d+)\+{0,1}([+-]{0,1}\d+)){0,1}", 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[2]}{value_list[2]}{separator_list[3]}{value_list[3]}"
|
||||
width = int(result.group(2)) if result.group(2) is not None else None
|
||||
height = int(result.group(3)) if result.group(3) is not None else None
|
||||
x = int(result.group(5)) if result.group(5) is not None else None
|
||||
y = int(result.group(6)) if result.group(6) is not None else None
|
||||
|
||||
return width, height, x, y
|
||||
|
||||
def apply_geometry_scaling(self, geometry_string: str) -> str:
|
||||
width, height, x, y = self.parse_geometry_string(geometry_string)
|
||||
|
||||
if x is None and y is None: # no <x> and <y> in geometry_string
|
||||
return f"{round(width * self.window_scaling)}x{round(height * self.window_scaling)}"
|
||||
|
||||
elif width is None and height is None: # no <width> and <height> in geometry_string
|
||||
return f"+{x}+{y}"
|
||||
|
||||
else:
|
||||
return f"{round(width * self.window_scaling)}x{round(height * self.window_scaling)}+{x}+{y}"
|
||||
|
||||
def reverse_geometry_scaling(self, scaled_geometry_string: str) -> str:
|
||||
width, height, x, y = self.parse_geometry_string(scaled_geometry_string)
|
||||
|
||||
if x is None and y is None: # no <x> and <y> in geometry_string
|
||||
return f"{round(width / self.window_scaling)}x{round(height / self.window_scaling)}"
|
||||
|
||||
elif width is None and height is None: # no <width> and <height> in geometry_string
|
||||
return f"+{x}+{y}"
|
||||
|
||||
else:
|
||||
return f"{round(width / self.window_scaling)}x{round(height / self.window_scaling)}+{x}+{y}"
|
||||
|
||||
def apply_window_scaling(self, value):
|
||||
if isinstance(value, (int, float)):
|
||||
@ -115,23 +142,22 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
else:
|
||||
return value
|
||||
|
||||
def geometry(self, geometry_string: str = None):
|
||||
if geometry_string is not None:
|
||||
super().geometry(self.apply_geometry_scaling(geometry_string))
|
||||
|
||||
# update width and height attributes
|
||||
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_height = max(self.min_height, min(numbers[1], self.max_height))
|
||||
else:
|
||||
return self.reverse_geometry_scaling(super().geometry())
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.set_appearance_mode)
|
||||
ScalingTracker.remove_window(self.set_scaling, self)
|
||||
self.disable_macos_dark_title_bar()
|
||||
super().destroy()
|
||||
|
||||
def withdraw(self):
|
||||
if self.windows_set_titlebar_color_called:
|
||||
self.withdraw_called_after_windows_set_titlebar_color = True
|
||||
super().withdraw()
|
||||
|
||||
def iconify(self):
|
||||
if self.windows_set_titlebar_color_called:
|
||||
self.iconify_called_after_windows_set_titlebar_color = True
|
||||
super().iconify()
|
||||
|
||||
def resizable(self, *args, **kwargs):
|
||||
super().resizable(*args, **kwargs)
|
||||
self.last_resizable_args = (args, kwargs)
|
||||
@ -223,6 +249,7 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
|
||||
if sys.platform.startswith("win") and not Settings.deactivate_windows_window_header_manipulation:
|
||||
|
||||
self.state_before_windows_set_titlebar_color = self.state()
|
||||
super().withdraw() # hide window so that it can be redrawn after the titlebar change so that the color change is visible
|
||||
super().update()
|
||||
|
||||
@ -250,7 +277,30 @@ class CTkToplevel(tkinter.Toplevel):
|
||||
except Exception as err:
|
||||
print(err)
|
||||
|
||||
self.deiconify()
|
||||
self.windows_set_titlebar_color_called = True
|
||||
self.after(5, self.revert_withdraw_after_windows_set_titlebar_color)
|
||||
|
||||
def revert_withdraw_after_windows_set_titlebar_color(self):
|
||||
""" if in a short time (5ms) after """
|
||||
if self.windows_set_titlebar_color_called:
|
||||
|
||||
if self.withdraw_called_after_windows_set_titlebar_color:
|
||||
pass # leave it withdrawed
|
||||
elif self.iconify_called_after_windows_set_titlebar_color:
|
||||
super().iconify()
|
||||
else:
|
||||
if self.state_before_windows_set_titlebar_color == "normal":
|
||||
self.deiconify()
|
||||
elif self.state_before_windows_set_titlebar_color == "iconic":
|
||||
self.iconify()
|
||||
elif self.state_before_windows_set_titlebar_color == "zoomed":
|
||||
self.state("zoomed")
|
||||
else:
|
||||
self.state(self.state_before_windows_set_titlebar_color) # other states
|
||||
|
||||
self.windows_set_titlebar_color_called = False
|
||||
self.withdraw_called_after_windows_set_titlebar_color = False
|
||||
self.iconify_called_after_windows_set_titlebar_color = False
|
||||
|
||||
def set_appearance_mode(self, mode_string):
|
||||
if mode_string.lower() == "dark":
|
||||
|
@ -1,6 +1,5 @@
|
||||
import tkinter
|
||||
import customtkinter
|
||||
from PIL import Image, ImageTk # <- import PIL for the images
|
||||
from PIL import Image, ImageTk
|
||||
import os
|
||||
|
||||
PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
@ -8,57 +7,61 @@ PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
||||
app.geometry("450x260")
|
||||
app.title("CustomTkinter example_button_images.py")
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.geometry("450x260")
|
||||
self.title("CustomTkinter example_button_images.py")
|
||||
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1, minsize=200)
|
||||
|
||||
self.frame_1 = customtkinter.CTkFrame(master=self, width=250, height=240, corner_radius=15)
|
||||
self.frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
|
||||
self.frame_1.grid_columnconfigure(0, weight=1)
|
||||
self.frame_1.grid_columnconfigure(1, weight=1)
|
||||
|
||||
self.settings_image = self.load_image("/test_images/settings.png", 20)
|
||||
self.bell_image = self.load_image("/test_images/bell.png", 20)
|
||||
self.add_folder_image = self.load_image("/test_images/add-folder.png", 20)
|
||||
self.add_list_image = self.load_image("/test_images/add-folder.png", 20)
|
||||
self.add_user_image = self.load_image("/test_images/add-user.png", 20)
|
||||
self.chat_image = self.load_image("/test_images/chat.png", 20)
|
||||
self.home_image = self.load_image("/test_images/home.png", 20)
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(master=self.frame_1, image=self.add_folder_image, text="Add Folder", height=32,
|
||||
compound="right", command=self.button_function)
|
||||
self.button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=(20, 10), sticky="ew")
|
||||
|
||||
self.button_2 = customtkinter.CTkButton(master=self.frame_1, image=self.add_list_image, text="Add Item", height=32,
|
||||
compound="right", fg_color="#D35B58", hover_color="#C77C78",
|
||||
command=self.button_function)
|
||||
self.button_2.grid(row=2, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
|
||||
|
||||
self.button_3 = customtkinter.CTkButton(master=self.frame_1, image=self.chat_image, text="", width=40, height=40,
|
||||
corner_radius=10, fg_color="gray40", hover_color="gray25",
|
||||
command=self.button_function)
|
||||
self.button_3.grid(row=3, column=0, columnspan=1, padx=20, pady=10, sticky="w")
|
||||
|
||||
self.button_4 = customtkinter.CTkButton(master=self.frame_1, image=self.home_image, text="", width=40, height=40,
|
||||
corner_radius=10, fg_color="gray40", hover_color="gray25",
|
||||
command=self.button_function)
|
||||
self.button_4.grid(row=3, column=1, columnspan=1, padx=20, pady=10, sticky="e")
|
||||
|
||||
self.button_5 = customtkinter.CTkButton(master=self, image=self.add_user_image, text="Add User", width=130, height=60, border_width=2,
|
||||
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray84", "gray25"),
|
||||
hover_color="#C77C78", command=self.button_function)
|
||||
self.button_5.grid(row=0, column=1, padx=20, pady=20)
|
||||
|
||||
def load_image(self, path, image_size):
|
||||
""" load rectangular image with path relative to PATH """
|
||||
return ImageTk.PhotoImage(Image.open(PATH + path).resize((image_size, image_size)))
|
||||
|
||||
def button_function(self):
|
||||
print("button pressed")
|
||||
|
||||
|
||||
def button_function():
|
||||
print("button pressed")
|
||||
|
||||
|
||||
# load images as PhotoImage
|
||||
image_size = 20
|
||||
|
||||
settings_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/settings.png").resize((image_size, image_size)))
|
||||
bell_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/bell.png").resize((image_size, image_size)))
|
||||
|
||||
add_folder_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-folder.png").resize((image_size, image_size), Image.ANTIALIAS))
|
||||
add_list_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-list.png").resize((image_size, image_size), Image.ANTIALIAS))
|
||||
add_user_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-user.png").resize((image_size, image_size), Image.ANTIALIAS))
|
||||
chat_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/chat.png").resize((image_size, image_size), Image.ANTIALIAS))
|
||||
home_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/home.png").resize((image_size, image_size), Image.ANTIALIAS))
|
||||
|
||||
app.grid_rowconfigure(0, weight=1)
|
||||
app.grid_columnconfigure(0, weight=1, minsize=200)
|
||||
|
||||
frame_1 = customtkinter.CTkFrame(master=app, width=250, height=240, corner_radius=15)
|
||||
frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
|
||||
|
||||
frame_1.grid_columnconfigure(0, weight=1)
|
||||
frame_1.grid_columnconfigure(1, weight=1)
|
||||
frame_1.grid_rowconfigure(0, minsize=10) # add empty row for spacing
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=frame_1, image=add_folder_image, text="Add Folder", width=190, height=40,
|
||||
compound="right", command=button_function)
|
||||
button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
|
||||
|
||||
button_2 = customtkinter.CTkButton(master=frame_1, image=add_list_image, text="Add Item", width=190, height=40,
|
||||
compound="right", fg_color="#D35B58", hover_color="#C77C78",
|
||||
command=button_function)
|
||||
button_2.grid(row=2, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
|
||||
|
||||
button_3 = customtkinter.CTkButton(master=frame_1, image=chat_image, text="", width=50, height=50,
|
||||
corner_radius=10, fg_color="gray40", hover_color="gray25", command=button_function)
|
||||
button_3.grid(row=3, column=0, columnspan=1, padx=20, pady=10, sticky="w")
|
||||
|
||||
button_4 = customtkinter.CTkButton(master=frame_1, image=home_image, text="", width=50, height=50,
|
||||
corner_radius=10, fg_color="gray40", hover_color="gray25", command=button_function)
|
||||
button_4.grid(row=3, column=1, columnspan=1, padx=20, pady=10, sticky="e")
|
||||
|
||||
button_5 = customtkinter.CTkButton(master=app, image=add_user_image, text="Add User", width=130, height=70, border_width=3,
|
||||
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray84", "gray25"), hover_color="#C77C78",
|
||||
command=button_function)
|
||||
button_5.grid(row=0, column=1, padx=20, pady=20)
|
||||
|
||||
app.mainloop()
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.mainloop()
|
||||
|
@ -28,7 +28,6 @@ progressbar_1.pack(pady=12, padx=10)
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=frame_1, command=button_callback)
|
||||
button_1.pack(pady=12, padx=10)
|
||||
button_1.configure(state='disabled')
|
||||
|
||||
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_callback, from_=0, to=1)
|
||||
slider_1.pack(pady=12, padx=10)
|
||||
|
@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
||||
github_url = "https://github.com/TomSchimansky/CustomTkinter"
|
||||
|
||||
[tool.tbump.version]
|
||||
current = "4.5.10"
|
||||
current = "4.5.11"
|
||||
|
||||
# Example of a semver regexp.
|
||||
# Make sure this matches current_version before
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = customtkinter
|
||||
version = 4.5.10
|
||||
version = 4.5.11
|
||||
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_content_type = text/markdown
|
||||
|
@ -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")
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
import customtkinter
|
||||
import sys
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x240")
|
||||
|
||||
|
||||
def change_appearance_mode():
|
||||
# test appearance mode change while withdrawn
|
||||
app.after(500, app.withdraw)
|
||||
app.after(1500, lambda: customtkinter.set_appearance_mode("light"))
|
||||
app.after(2500, app.deiconify)
|
||||
|
||||
# test appearance mode change while iconified
|
||||
app.after(3500, app.iconify)
|
||||
app.after(4500, lambda: customtkinter.set_appearance_mode("dark"))
|
||||
app.after(5500, app.deiconify)
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
# test appearance mode change while zoomed
|
||||
app.after(6500, lambda: app.state("zoomed"))
|
||||
app.after(7500, lambda: customtkinter.set_appearance_mode("light"))
|
||||
app.after(8500, lambda: app.state("normal"))
|
||||
|
||||
|
||||
button_1 = customtkinter.CTkButton(app, text="start test", command=change_appearance_mode)
|
||||
button_1.pack(pady=20, padx=20)
|
||||
|
||||
app.mainloop()
|
@ -0,0 +1,9 @@
|
||||
import customtkinter
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x240")
|
||||
|
||||
app.iconify()
|
||||
app.after(2000, app.deiconify)
|
||||
|
||||
app.mainloop()
|
@ -0,0 +1,9 @@
|
||||
import customtkinter
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x240")
|
||||
|
||||
app.withdraw()
|
||||
app.after(2000, app.deiconify)
|
||||
|
||||
app.mainloop()
|
@ -0,0 +1,27 @@
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x240")
|
||||
|
||||
|
||||
def change_appearance_mode():
|
||||
# test zoom with withdraw
|
||||
app.after(1000, lambda: app.state("zoomed"))
|
||||
app.after(2000, app.withdraw)
|
||||
app.after(3000, app.deiconify)
|
||||
app.after(4000, lambda: app.state("normal"))
|
||||
|
||||
# test zoom with iconify
|
||||
app.after(5000, lambda: app.state("zoomed"))
|
||||
app.after(6000, app.iconify)
|
||||
app.after(7000, app.deiconify)
|
||||
app.after(8000, lambda: app.state("normal"))
|
||||
|
||||
|
||||
button_1 = customtkinter.CTkButton(app, text="start test", command=change_appearance_mode)
|
||||
button_1.pack(pady=20, padx=20)
|
||||
|
||||
app.mainloop()
|
@ -1,22 +1,49 @@
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
class ExampleApp(customtkinter.CTk):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
class ToplevelWindow(customtkinter.CTkToplevel):
|
||||
def __init__(self, *args, closing_event=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.protocol("WM_DELETE_WINDOW", self.closing)
|
||||
self.geometry("500x300")
|
||||
self.closing_event = closing_event
|
||||
|
||||
self.geometry("500x400")
|
||||
self.label = customtkinter.CTkLabel(self, text="ToplevelWindow")
|
||||
self.label.pack(padx=20, pady=20)
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(self, text="Create CTkToplevel", command=self.create_toplevel)
|
||||
self.button_1 = customtkinter.CTkButton(self, text="set dark", command=lambda: customtkinter.set_appearance_mode("dark"))
|
||||
self.button_1.pack(side="top", padx=40, pady=40)
|
||||
|
||||
def create_toplevel(self):
|
||||
window = customtkinter.CTkToplevel(self)
|
||||
window.geometry("400x200")
|
||||
|
||||
label = customtkinter.CTkLabel(window, text="CTkToplevel window")
|
||||
label.pack(side="top", fill="both", expand=True, padx=40, pady=40)
|
||||
def closing(self):
|
||||
self.destroy()
|
||||
if self.closing_event is not None:
|
||||
self.closing_event()
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
app.mainloop()
|
||||
class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.geometry("500x400")
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(self, text="Open CTkToplevel", command=self.open_toplevel)
|
||||
self.button_1.pack(side="top", padx=40, pady=40)
|
||||
self.button_2 = customtkinter.CTkButton(self, text="iconify toplevel", command=lambda: self.toplevel_window.iconify())
|
||||
self.button_2.pack(side="top", padx=40, pady=40)
|
||||
self.button_3 = customtkinter.CTkButton(self, text="set light", command=lambda: customtkinter.set_appearance_mode("light"))
|
||||
self.button_3.pack(side="top", padx=40, pady=40)
|
||||
|
||||
self.toplevel_window = None
|
||||
|
||||
def open_toplevel(self):
|
||||
if self.toplevel_window is None: # create toplevel window only if not already open
|
||||
self.toplevel_window = ToplevelWindow(self, closing_event=self.toplevel_close_event)
|
||||
|
||||
def toplevel_close_event(self):
|
||||
self.toplevel_window = None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.mainloop()
|
||||
|
@ -0,0 +1,35 @@
|
||||
import customtkinter
|
||||
import sys
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x400+300+300")
|
||||
|
||||
toplevel = customtkinter.CTkToplevel(app)
|
||||
toplevel.geometry("350x240+800+300")
|
||||
|
||||
|
||||
def change_appearance_mode():
|
||||
# test appearance mode change while withdrawn
|
||||
app.after(500, toplevel.withdraw)
|
||||
app.after(1500, lambda: customtkinter.set_appearance_mode("light"))
|
||||
app.after(2500, toplevel.deiconify)
|
||||
|
||||
# test appearance mode change while iconified
|
||||
app.after(3500, toplevel.iconify)
|
||||
app.after(4500, lambda: customtkinter.set_appearance_mode("dark"))
|
||||
app.after(5500, toplevel.deiconify)
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
# test appearance mode change while zoomed
|
||||
app.after(6500, lambda: toplevel.state("zoomed"))
|
||||
app.after(7500, lambda: customtkinter.set_appearance_mode("light"))
|
||||
app.after(8500, lambda: toplevel.state("normal"))
|
||||
|
||||
|
||||
button_1 = customtkinter.CTkButton(app, text="start test", command=change_appearance_mode)
|
||||
button_1.pack(pady=20, padx=20)
|
||||
|
||||
app.mainloop()
|
@ -0,0 +1,12 @@
|
||||
import customtkinter
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x400+300+300")
|
||||
|
||||
toplevel = customtkinter.CTkToplevel(app)
|
||||
toplevel.geometry("350x240+800+300")
|
||||
|
||||
toplevel.iconify()
|
||||
toplevel.after(2000, toplevel.deiconify)
|
||||
|
||||
app.mainloop()
|
@ -0,0 +1,12 @@
|
||||
import customtkinter
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x400+300+300")
|
||||
|
||||
toplevel = customtkinter.CTkToplevel(app)
|
||||
toplevel.geometry("350x240+800+300")
|
||||
|
||||
toplevel.withdraw()
|
||||
toplevel.after(2000, toplevel.deiconify)
|
||||
|
||||
app.mainloop()
|
@ -0,0 +1,29 @@
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x400+300+300")
|
||||
|
||||
toplevel = customtkinter.CTkToplevel(app)
|
||||
toplevel.geometry("350x240+800+300")
|
||||
|
||||
|
||||
def change_appearance_mode():
|
||||
# test zoom with withdraw
|
||||
app.after(1000, lambda: toplevel.state("zoomed"))
|
||||
app.after(2000, toplevel.withdraw)
|
||||
app.after(3000, toplevel.deiconify)
|
||||
app.after(4000, lambda: toplevel.state("normal"))
|
||||
|
||||
# test zoom with iconify
|
||||
app.after(5000, lambda: toplevel.state("zoomed"))
|
||||
app.after(6000, toplevel.iconify)
|
||||
app.after(7000, toplevel.deiconify)
|
||||
app.after(8000, lambda: toplevel.state("normal"))
|
||||
|
||||
|
||||
button_1 = customtkinter.CTkButton(app, text="start test", command=change_appearance_mode)
|
||||
button_1.pack(pady=20, padx=20)
|
||||
|
||||
app.mainloop()
|
@ -1,21 +0,0 @@
|
||||
import customtkinter
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x240")
|
||||
|
||||
|
||||
def button_function():
|
||||
|
||||
top = customtkinter.CTkToplevel(app)
|
||||
|
||||
app.after(1000, top.iconify) # hide toplevel
|
||||
app.after(1500, top.deiconify) # show toplevel
|
||||
app.after(2500, app.iconify) # hide app
|
||||
app.after(3000, app.deiconify) # show app
|
||||
app.after(4000, app.destroy) # destroy everything
|
||||
|
||||
|
||||
button = customtkinter.CTkButton(app, command=button_function)
|
||||
button.pack(pady=20, padx=20)
|
||||
|
||||
app.mainloop()
|
@ -1,71 +0,0 @@
|
||||
import customtkinter
|
||||
import tkinter
|
||||
import sys
|
||||
|
||||
|
||||
class CTkMenu(tkinter.Toplevel):
|
||||
def __init__(self, master, x, y, options):
|
||||
super().__init__()
|
||||
|
||||
self.overrideredirect(True)
|
||||
self.geometry(f"120x{len(options) * (25 + 3) + 3}+{x}+{y}")
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
self.overrideredirect(False)
|
||||
self.wm_attributes("-transparent", True) # turn off shadow
|
||||
self.config(bg='systemTransparent') # transparent bg
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
|
||||
elif sys.platform.startswith("win"):
|
||||
self.configure(bg="#FFFFF1")
|
||||
self.wm_attributes("-transparent", "#FFFFF1")
|
||||
self.focus()
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
|
||||
overwrite_preferred_drawing_method="circle_shapes")
|
||||
else:
|
||||
self.configure(bg="#FFFFF1")
|
||||
self.wm_attributes("-transparent", "#FFFFF1")
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740",
|
||||
overwrite_preferred_drawing_method="circle_shapes")
|
||||
|
||||
self.frame.grid(row=0, column=0, sticky="nsew", rowspan=len(options) + 1, columnspan=1, ipadx=0, ipady=0)
|
||||
|
||||
self.frame.grid_rowconfigure(len(options) + 1, minsize=3)
|
||||
self.frame.grid_columnconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.buttons = []
|
||||
for index, option in enumerate(options):
|
||||
button = customtkinter.CTkButton(self.frame, text=option, height=25, width=108, fg_color="#333740", text_color="gray74",
|
||||
hover_color="gray28", corner_radius=4, command=self.button_click)
|
||||
button.text_label.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="w")
|
||||
button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
|
||||
self.buttons.append(button)
|
||||
|
||||
self.bind("<FocusOut>", self.focus_loss_event)
|
||||
self.frame.canvas.bind("<Button-1>", self.focus_loss_event)
|
||||
|
||||
def focus_loss_event(self, event):
|
||||
print("focus loss")
|
||||
self.destroy()
|
||||
# self.update()
|
||||
|
||||
def button_click(self):
|
||||
print("button press")
|
||||
self.destroy()
|
||||
# self.update()
|
||||
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("600x500")
|
||||
|
||||
|
||||
def open_menu():
|
||||
menu = CTkMenu(app, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
|
||||
|
||||
button = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
|
||||
button.pack(pady=20)
|
||||
|
||||
button_2 = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
|
||||
button_2.pack(pady=60)
|
||||
|
||||
app.mainloop()
|
37
test/manual_integration_tests/test_window_geometry.py
Normal file
37
test/manual_integration_tests/test_window_geometry.py
Normal file
@ -0,0 +1,37 @@
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_window_scaling(1.3)
|
||||
|
||||
app = customtkinter.CTk()
|
||||
toplevel = customtkinter.CTkToplevel(app)
|
||||
|
||||
|
||||
app.after(1000, lambda: app.geometry("300x300"))
|
||||
app.after(2000, lambda: app.geometry("-100-100"))
|
||||
app.after(3000, lambda: app.geometry("+-100+-100"))
|
||||
app.after(4000, lambda: app.geometry("+100+100"))
|
||||
app.after(5000, lambda: app.geometry("300x300-100-100"))
|
||||
app.after(6000, lambda: app.geometry("300x300+-100+-100"))
|
||||
app.after(7000, lambda: app.geometry("300x300+100+100"))
|
||||
|
||||
app.after(8000, lambda: app.geometry("400x400"))
|
||||
app.after(9000, lambda: app.geometry("+400+400"))
|
||||
|
||||
|
||||
app.after(10000, lambda: toplevel.geometry("300x300"))
|
||||
app.after(11000, lambda: toplevel.geometry("-100-100"))
|
||||
app.after(12000, lambda: toplevel.geometry("+-100+-100"))
|
||||
app.after(13000, lambda: toplevel.geometry("+100+100"))
|
||||
app.after(14000, lambda: toplevel.geometry("300x300-100-100"))
|
||||
app.after(15000, lambda: toplevel.geometry("300x300+-100+-100"))
|
||||
app.after(16000, lambda: toplevel.geometry("300x300+100+100"))
|
||||
|
||||
app.after(17000, lambda: toplevel.geometry("300x300"))
|
||||
app.after(18000, lambda: toplevel.geometry("+500+500"))
|
||||
|
||||
|
||||
app.after(19000, lambda: print("app:", app.geometry()))
|
||||
app.after(19000, lambda: print("toplevel:", toplevel.geometry()))
|
||||
|
||||
|
||||
app.mainloop()
|
Reference in New Issue
Block a user