Untitled
unknown
plain_text
5 months ago
5.0 kB
3
Indexable
class SettingsMenu(ctk.CTkFrame): def __init__(self, parent, dark_mode): # Fixed dimensions self.menu_width = 280 self.menu_height = 600 super().__init__( parent, fg_color='#1c1c1e' if dark_mode else '#f5f5f7', width=self.menu_width, height=self.menu_height ) self.parent = parent self.dark_mode = dark_mode self.is_open = False self.animation_running = False self.current_width = 0 self.target_width = self.menu_width # Add border color based on dark mode self.border_color = '#2c2c2e' if dark_mode else '#e5e5e7' self.configure(border_width=2, border_color=self.border_color) # Place the frame initially off-screen self.place(relx=1, rely=0, x=self.menu_width, y=0, anchor='ne') # Create settings content self.create_menu_content() # Create settings button try: is_light_bg = not dark_mode icon_suffix = "-b" if is_light_bg else "-w" icon_image = ctk.CTkImage( light_image=Image.open(f"icons/settings{icon_suffix}.png"), dark_image=Image.open(f"icons/settings{icon_suffix}.png"), size=(30, 30) ) self.settings_button = ctk.CTkButton( self.parent, image=icon_image, text="", width=30, height=30, fg_color="transparent", hover_color='#2c2c2e' if dark_mode else '#e5e5e7', command=self.toggle_menu ) self.settings_button.place(relx=0.97, rely=0.05, anchor='center') except Exception as e: print(f"Error loading settings icon: {e}") self.settings_button = ctk.CTkButton( self.parent, text="âš™", width=30, height=30, fg_color="transparent", hover_color='#2c2c2e' if dark_mode else '#e5e5e7', command=self.toggle_menu ) self.settings_button.place(relx=0.97, rely=0.04, anchor='center') # Bind click event to parent window self.parent.bind("<Button-1>", self.check_click_location) def check_click_location(self, event): if self.is_open: # Get the menu's position and dimensions menu_x = self.winfo_x() menu_width = self.winfo_width() # Check if click is outside the menu if event.x < menu_x: self.close_menu() def create_menu_content(self): root = self.winfo_toplevel() current_language = root.LANGUAGE # Title title = ctk.CTkLabel( self, text=TRANSLATIONS[current_language]['settings'], font=("Dongle", 24, "bold"), text_color='white' if self.dark_mode else 'black' ) title.pack(pady=(20, 40), padx=20, anchor='w') # Appearance section appearance_label = ctk.CTkLabel( self, text=TRANSLATIONS[current_language]['appearance'], font=("Dongle", 20), text_color='white' if self.dark_mode else 'black' ) appearance_label.pack(padx=20, anchor='w') # Dark mode switch self.dark_mode_switch = ctk.CTkSwitch( self, text=TRANSLATIONS[current_language]['dark_mode'], command=self.toggle_dark_mode, font=("Dongle", 16), fg_color='#34c759', progress_color='#34c759' ) self.dark_mode_switch.pack(pady=(10, 20), padx=20, anchor='w') self.dark_mode_switch.select() if self.dark_mode else self.dark_mode_switch.deselect() # Language section language_label = ctk.CTkLabel( self, text=TRANSLATIONS[current_language]['language'], font=("Dongle", 20), text_color='white' if self.dark_mode else 'black' ) language_label.pack(padx=20, anchor='w') # Language selection self.language_var = ctk.StringVar(value=current_language) self.language_menu = ctk.CTkOptionMenu( self, values=['EN', 'DE'], command=self.change_language, variable=self.language_var, font=("Dongle", 16), fg_color='#2c2c2e' if self.dark_mode else '#e5e5e7', button_color='#3a3a3c' if self.dark_mode else '#d1d1d6', button_hover_color='#3a3a3c' if self.dark_mode else '#d1d1d6', ) self.language_menu.pack(pady=(10, 20), padx=20, anchor='w')
Editor is loading...
Leave a Comment