updated test_new_menu_design.py

This commit is contained in:
Tom Schimansky 2022-05-24 13:50:34 +02:00
parent f49c83d2dc
commit 4b3b406250
2 changed files with 31 additions and 29 deletions

View File

@ -4,14 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [4.1.0] - 2022-05-24
### Added
- Configure width and height for frame, button, label, progressbar, slider, entry
## [4.0.0] - 2022-05-22
### Added
- This changelog file
- Adopted semantic versioning
- Added HighDPI scaling to all widgets and geometry managers (place, pack, grid)
- Restructured CTkSettings and renamed a few manager classes
### Changed
- Orientation attribute for slider and progressbar
### Removed
- A few unnecessary tests

View File

@ -1,53 +1,52 @@
import customtkinter
import tkinter
# customtkinter.set_appearance_mode("light")
app = customtkinter.CTk()
app.geometry("600x500")
menu = tkinter.Menu(tearoff=0, bd=0, relief=tkinter.FLAT, activeforeground="red")
menu.add_command(label="System")
menu.add_command(label="Light")
menu.add_command(label="Dark")
class CTkMenu(tkinter.Toplevel):
def __init__(self, master, x, y, options):
super().__init__(bg="black")
super().overrideredirect(True)
#self.wm_attributes("-transparentcolor", "black")
super().geometry(f"120x{len(options) * (25 + 4) + 4}+{x}+{y}")
super().lift()
super().transient(master)
self.resizable(False, False)
super().focus_force()
self.focus()
super().__init__()
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=10, border_color="gray4", fg_color="#333740")
self.frame.grid(row=0, column=0, sticky="nsew", rowspan=len(options) + 2, columnspan=1)
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.bind("<FocusOut>", self.focus_loss_event)
self.frame.grid_rowconfigure(0, minsize=2)
self.frame.grid_rowconfigure(len(options) + 1, minsize=2)
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=6, border_color="gray4", fg_color="#333740")
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, height=25, width=108, fg_color="#333740", text_color="gray74", hover_color="#272A2E", corner_radius=8)
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 + 1, column=0, padx=4, pady=2)
button.grid(row=index, column=0, padx=(3, 3), pady=(3, 0), columnspan=1, rowspan=1, sticky="ew")
self.buttons.append(button)
# master.bind("<Configure>", self.window_drag())
def focus_loss_event(self, event):
print("focus loss")
self.destroy()
self.update()
def button_click(self):
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"])
print(menu)
button = customtkinter.CTkButton(command=open_menu, height=50)
button = customtkinter.CTkButton(command=open_menu, height=30, corner_radius=6)
button.pack(pady=20)
app.mainloop()