mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # test/manual_integration_tests/test_new_menu_design.py
This commit is contained in:
commit
fd8135129c
@ -162,10 +162,11 @@ class ScalingTracker:
|
|||||||
def check_dpi_scaling(cls):
|
def check_dpi_scaling(cls):
|
||||||
# check for every window if scaling value changed
|
# check for every window if scaling value changed
|
||||||
for window in cls.window_widgets_dict:
|
for window in cls.window_widgets_dict:
|
||||||
current_dpi_scaling_value = cls.get_window_dpi_scaling(window)
|
if window.winfo_exists():
|
||||||
if current_dpi_scaling_value != cls.window_dpi_scaling_dict[window]:
|
current_dpi_scaling_value = cls.get_window_dpi_scaling(window)
|
||||||
cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value
|
if current_dpi_scaling_value != cls.window_dpi_scaling_dict[window]:
|
||||||
cls.update_scaling_callbacks_for_window(window)
|
cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value
|
||||||
|
cls.update_scaling_callbacks_for_window(window)
|
||||||
|
|
||||||
# find an existing tkinter object for the next call of .after()
|
# find an existing tkinter object for the next call of .after()
|
||||||
for app in cls.window_widgets_dict.keys():
|
for app in cls.window_widgets_dict.keys():
|
||||||
|
@ -13,6 +13,7 @@ class CTkFrame(CTkBaseClass):
|
|||||||
corner_radius="default_theme",
|
corner_radius="default_theme",
|
||||||
width=200,
|
width=200,
|
||||||
height=200,
|
height=200,
|
||||||
|
overwrite_preferred_drawing_method: str = None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
||||||
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
|
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
|
||||||
@ -21,6 +22,7 @@ class CTkFrame(CTkBaseClass):
|
|||||||
# color
|
# color
|
||||||
self.border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color
|
self.border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color
|
||||||
|
|
||||||
|
# determine fg_color of frame
|
||||||
if fg_color == "default_theme":
|
if fg_color == "default_theme":
|
||||||
if isinstance(self.master, CTkFrame):
|
if isinstance(self.master, CTkFrame):
|
||||||
if self.master.fg_color == ThemeManager.theme["color"]["frame_low"]:
|
if self.master.fg_color == ThemeManager.theme["color"]["frame_low"]:
|
||||||
@ -43,6 +45,7 @@ class CTkFrame(CTkBaseClass):
|
|||||||
self.canvas.place(x=0, y=0, relwidth=1, relheight=1)
|
self.canvas.place(x=0, y=0, relwidth=1, relheight=1)
|
||||||
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
||||||
self.draw_engine = DrawEngine(self.canvas)
|
self.draw_engine = DrawEngine(self.canvas)
|
||||||
|
self._overwrite_preferred_drawing_method = overwrite_preferred_drawing_method
|
||||||
|
|
||||||
self.bind('<Configure>', self.update_dimensions_event)
|
self.bind('<Configure>', self.update_dimensions_event)
|
||||||
|
|
||||||
@ -77,7 +80,8 @@ class CTkFrame(CTkBaseClass):
|
|||||||
requires_recoloring = self.draw_engine.draw_rounded_rect_with_border(self.apply_widget_scaling(self.current_width),
|
requires_recoloring = self.draw_engine.draw_rounded_rect_with_border(self.apply_widget_scaling(self.current_width),
|
||||||
self.apply_widget_scaling(self.current_height),
|
self.apply_widget_scaling(self.current_height),
|
||||||
self.apply_widget_scaling(self.corner_radius),
|
self.apply_widget_scaling(self.corner_radius),
|
||||||
self.apply_widget_scaling(self.border_width))
|
self.apply_widget_scaling(self.border_width),
|
||||||
|
overwrite_preferred_drawing_method=self._overwrite_preferred_drawing_method)
|
||||||
|
|
||||||
if no_color_updates is False or requires_recoloring:
|
if no_color_updates is False or requires_recoloring:
|
||||||
if self.fg_color is None:
|
if self.fg_color is None:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import customtkinter
|
import customtkinter
|
||||||
import tkinter
|
import tkinter
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class CTkMenu(tkinter.Toplevel):
|
class CTkMenu(tkinter.Toplevel):
|
||||||
@ -7,14 +8,25 @@ class CTkMenu(tkinter.Toplevel):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.overrideredirect(True)
|
self.overrideredirect(True)
|
||||||
self.overrideredirect(False)
|
|
||||||
self.wm_attributes("-transparent", True) # turn off shadow
|
|
||||||
self.config(bg='systemTransparent') # transparent bg
|
|
||||||
self.geometry(f"120x{len(options) * (25 + 3) + 3}+{x}+{y}")
|
self.geometry(f"120x{len(options) * (25 + 3) + 3}+{x}+{y}")
|
||||||
self.bind("<FocusOut>", self.focus_loss_event)
|
|
||||||
self.focus_force()
|
|
||||||
|
|
||||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
|
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(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_rowconfigure(len(options) + 1, minsize=3)
|
||||||
@ -29,14 +41,18 @@ class CTkMenu(tkinter.Toplevel):
|
|||||||
button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
|
button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
|
||||||
self.buttons.append(button)
|
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):
|
def focus_loss_event(self, event):
|
||||||
print("focus loss")
|
print("focus loss")
|
||||||
self.destroy()
|
self.destroy()
|
||||||
self.update()
|
# self.update()
|
||||||
|
|
||||||
def button_click(self):
|
def button_click(self):
|
||||||
|
print("button press")
|
||||||
self.destroy()
|
self.destroy()
|
||||||
self.update()
|
# self.update()
|
||||||
|
|
||||||
|
|
||||||
app = customtkinter.CTk()
|
app = customtkinter.CTk()
|
||||||
@ -46,8 +62,10 @@ app.geometry("600x500")
|
|||||||
def open_menu():
|
def open_menu():
|
||||||
menu = CTkMenu(app, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
|
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 = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
|
||||||
button.pack(pady=20)
|
button.pack(pady=20)
|
||||||
|
|
||||||
|
button_2 = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
|
||||||
|
button_2.pack(pady=60)
|
||||||
|
|
||||||
app.mainloop()
|
app.mainloop()
|
||||||
|
Loading…
Reference in New Issue
Block a user