|
| 1 | +import os |
| 2 | +import tkinter |
| 3 | + |
| 4 | +import customtkinter |
| 5 | +from PIL import Image |
| 6 | + |
| 7 | +customtkinter.set_appearance_mode("Dark") |
| 8 | +customtkinter.set_default_color_theme("dark-blue") |
| 9 | + |
| 10 | +master = customtkinter.CTk() |
| 11 | +image_path = './theme/' |
| 12 | +theme_selector_dark_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "dark_theme.png")), size=(500, 410)) |
| 13 | +theme_selector_light_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "light_theme.png")), size=(500, 410)) |
| 14 | +theme_selector_classic_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "classic_theme.png")), size=(500, 410)) |
| 15 | + |
| 16 | +def launchUI(theme_radio_var): |
| 17 | + print(f'Get theme radio var: {theme_radio_var.get()}') |
| 18 | + if theme_radio_var.get() == 1: |
| 19 | + print('Activate light mode.') |
| 20 | + os.system("./launchUI.bash light &") |
| 21 | + elif theme_radio_var.get() == 2: |
| 22 | + print('Activate classic mode.') |
| 23 | + os.system("./launchUI.bash classic &") |
| 24 | + else: |
| 25 | + print('Activate dark mode.') |
| 26 | + os.system("./launchUI.bash &") |
| 27 | + master.destroy() |
| 28 | + |
| 29 | + |
| 30 | +def switchUI(theme_radio_var, radiobutton_frame, launch_button, theme_selector_image_label): |
| 31 | + theme_selector_image_label.forget() |
| 32 | + if theme_radio_var.get() == 1: |
| 33 | + print('light mode.') |
| 34 | + customtkinter.set_appearance_mode("light") |
| 35 | + customtkinter.set_default_color_theme("dark-blue") |
| 36 | + radiobutton_frame.configure(fg_color='#D9D9D9') |
| 37 | + launch_button.configure(fg_color='#3A7EBF') |
| 38 | + theme_selector_image_label = customtkinter.CTkLabel(main_frame, text="", image=theme_selector_light_image, |
| 39 | + compound="bottom", anchor="center") |
| 40 | + theme_selector_image_label.grid(row=1, column=0) |
| 41 | + elif theme_radio_var.get() == 2: |
| 42 | + print('classic mode.') |
| 43 | + customtkinter.set_appearance_mode("light") |
| 44 | + # customtkinter.set_default_color_theme("green") |
| 45 | + radiobutton_frame.configure(fg_color='#F0F0F0') |
| 46 | + launch_button.configure(fg_color='#808080') |
| 47 | + theme_selector_image_label = customtkinter.CTkLabel(main_frame, text="", image=theme_selector_classic_image, |
| 48 | + compound="bottom", anchor="center") |
| 49 | + theme_selector_image_label.grid(row=1, column=0) |
| 50 | + else: |
| 51 | + print('dark mode.') |
| 52 | + customtkinter.set_appearance_mode("dark") |
| 53 | + customtkinter.set_default_color_theme("dark-blue") |
| 54 | + radiobutton_frame.configure(fg_color='#292929') |
| 55 | + launch_button.configure(fg_color='#1F538D') |
| 56 | + theme_selector_image_label = customtkinter.CTkLabel(main_frame, text="", image=theme_selector_dark_image, |
| 57 | + compound="bottom", anchor="center") |
| 58 | + theme_selector_image_label.grid(row=1, column=0) |
| 59 | + |
| 60 | + |
| 61 | +# configure window |
| 62 | +master.title("Startup theme selector") |
| 63 | +master.geometry(f"{500}x{500}") |
| 64 | +master.resizable(False, False) |
| 65 | + |
| 66 | +main_frame = customtkinter.CTkFrame(master) |
| 67 | +main_frame.grid(row=0, column=0, sticky="nsew") |
| 68 | +main_frame.grid_rowconfigure(0, weight=1) |
| 69 | +main_frame.grid_rowconfigure(1, weight=3) |
| 70 | +main_frame.grid_columnconfigure(0, weight=1) |
| 71 | + |
| 72 | +radiobutton_frame = customtkinter.CTkFrame(main_frame) |
| 73 | +radiobutton_frame.grid(row=0, column=0, sticky="nsew") |
| 74 | + |
| 75 | +radiobutton_frame.grid_rowconfigure(0, weight=1) |
| 76 | +radiobutton_frame.grid_rowconfigure(1, weight=2) |
| 77 | +radiobutton_frame.grid_columnconfigure(0, weight=1) |
| 78 | +radiobutton_frame.grid_columnconfigure(1, weight=1) |
| 79 | +radiobutton_frame.grid_columnconfigure(2, weight=1) |
| 80 | + |
| 81 | +theme_radio_var = tkinter.IntVar(value=0) |
| 82 | + |
| 83 | +main_frame_label = customtkinter.CTkLabel(radiobutton_frame, text='Please choose the theme mode: ', font=customtkinter.CTkFont(size=15, weight="bold")) |
| 84 | +main_frame_label.grid(row=0, column=0, columnspan=2, padx=(10, 5), pady=(10, 10), sticky="w") |
| 85 | +launch_button = customtkinter.CTkButton(master=radiobutton_frame, text='LaunchUI', command=lambda: launchUI(theme_radio_var)) |
| 86 | +launch_button.grid(row=0, column=2, pady=(10, 10), sticky="w") |
| 87 | + |
| 88 | +theme_selector_image_label = customtkinter.CTkLabel(main_frame, text="", image=theme_selector_dark_image, compound="bottom", anchor="center") |
| 89 | +theme_selector_image_label.grid(row=1, column=0) |
| 90 | + |
| 91 | +# create radiobutton frame |
| 92 | +light_theme_button = customtkinter.CTkRadioButton(master=radiobutton_frame, text='Light', variable=theme_radio_var, value=1, command=lambda: switchUI(theme_radio_var, radiobutton_frame, launch_button, theme_selector_image_label)) |
| 93 | +light_theme_button.grid(row=1, column=0, pady=(10, 10), padx=(10,0), sticky="w") |
| 94 | +dark_theme_button = customtkinter.CTkRadioButton(master=radiobutton_frame, text='Dark', variable=theme_radio_var, value=0, command=lambda: switchUI(theme_radio_var, radiobutton_frame, launch_button, theme_selector_image_label)) |
| 95 | +dark_theme_button.grid(row=1, column=1, pady=(10, 10), padx=(10,0), sticky="w") |
| 96 | +classic_theme_button = customtkinter.CTkRadioButton(master=radiobutton_frame, text='Classic', variable=theme_radio_var, value=2, command=lambda: switchUI(theme_radio_var, radiobutton_frame, launch_button, theme_selector_image_label)) |
| 97 | +classic_theme_button.grid(row=1, column=2, pady=(10, 10), padx=(10,0), sticky="w") |
| 98 | + |
| 99 | +master.mainloop() |
| 100 | + |
| 101 | + |
0 commit comments