2021-03-05 22:27:34 +03:00
|
|
|
import tkinter
|
|
|
|
import tkinter.messagebox
|
|
|
|
import customtkinter
|
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
2022-03-13 03:37:22 +03:00
|
|
|
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
2022-03-09 16:49:44 +03:00
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2021-12-31 21:07:53 +03:00
|
|
|
class App(customtkinter.CTk):
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
WIDTH = 780
|
|
|
|
HEIGHT = 520
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2021-12-31 02:22:32 +03:00
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
self.title("CustomTkinter complex_example.py")
|
2022-03-05 04:01:07 +03:00
|
|
|
self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-04-18 00:51:33 +03:00
|
|
|
self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
# ============ create two frames ============
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-04-18 00:51:33 +03:00
|
|
|
# configure grid layout (2x1)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.grid_columnconfigure(1, weight=1)
|
2022-04-18 00:51:33 +03:00
|
|
|
self.grid_rowconfigure(0, weight=1)
|
2022-03-08 19:33:51 +03:00
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
self.frame_left = customtkinter.CTkFrame(master=self,
|
2022-02-23 03:47:34 +03:00
|
|
|
width=180,
|
|
|
|
corner_radius=0)
|
|
|
|
self.frame_left.grid(row=0, column=0, sticky="nswe")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
self.frame_right = customtkinter.CTkFrame(master=self)
|
2022-02-23 03:47:34 +03:00
|
|
|
self.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)
|
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
# ============ frame_left ============
|
|
|
|
|
2022-04-18 00:51:33 +03:00
|
|
|
# configure grid layout (1x11)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.frame_left.grid_rowconfigure(0, minsize=10) # empty row with minsize as spacing
|
|
|
|
self.frame_left.grid_rowconfigure(5, weight=1) # empty row as spacing
|
|
|
|
self.frame_left.grid_rowconfigure(8, minsize=20) # empty row with minsize as spacing
|
|
|
|
self.frame_left.grid_rowconfigure(11, minsize=10) # empty row with minsize as spacing
|
2022-02-23 03:47:34 +03:00
|
|
|
|
|
|
|
self.label_1 = customtkinter.CTkLabel(master=self.frame_left,
|
2022-02-24 02:19:40 +03:00
|
|
|
text="CustomTkinter",
|
2022-03-05 04:01:07 +03:00
|
|
|
text_font=("Roboto Medium", -16)) # font name and size in px
|
2022-02-23 03:47:34 +03:00
|
|
|
self.label_1.grid(row=1, column=0, pady=10, padx=10)
|
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
self.button_1 = customtkinter.CTkButton(master=self.frame_left,
|
2022-02-23 03:47:34 +03:00
|
|
|
text="CTkButton 1",
|
2022-03-08 19:33:51 +03:00
|
|
|
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
|
|
|
command=self.button_event)
|
2022-02-23 03:47:34 +03:00
|
|
|
self.button_1.grid(row=2, column=0, pady=10, padx=20)
|
2021-03-05 22:27:34 +03:00
|
|
|
|
|
|
|
self.button_2 = customtkinter.CTkButton(master=self.frame_left,
|
2022-02-23 03:47:34 +03:00
|
|
|
text="CTkButton 2",
|
2022-03-08 19:33:51 +03:00
|
|
|
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
|
|
|
command=self.button_event)
|
2022-02-23 03:47:34 +03:00
|
|
|
self.button_2.grid(row=3, column=0, pady=10, padx=20)
|
2021-03-05 22:27:34 +03:00
|
|
|
|
|
|
|
self.button_3 = customtkinter.CTkButton(master=self.frame_left,
|
2022-02-23 03:47:34 +03:00
|
|
|
text="CTkButton 3",
|
2022-03-08 19:33:51 +03:00
|
|
|
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
|
|
|
command=self.button_event)
|
2022-02-23 03:47:34 +03:00
|
|
|
self.button_3.grid(row=4, column=0, pady=10, padx=20)
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
self.switch_1 = customtkinter.CTkSwitch(master=self.frame_left)
|
|
|
|
self.switch_1.grid(row=9, column=0, pady=10, padx=20, sticky="w")
|
2022-02-21 17:35:08 +03:00
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
self.switch_2 = customtkinter.CTkSwitch(master=self.frame_left,
|
|
|
|
text="Dark Mode",
|
|
|
|
command=self.change_mode)
|
|
|
|
self.switch_2.grid(row=10, column=0, pady=10, padx=20, sticky="w")
|
2021-08-25 18:33:44 +03:00
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
# ============ frame_right ============
|
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
# configure grid layout (3x7)
|
2022-04-18 00:51:33 +03:00
|
|
|
self.frame_right.rowconfigure((0, 1, 2, 3), weight=1)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.frame_right.rowconfigure(7, weight=10)
|
2022-04-18 00:51:33 +03:00
|
|
|
self.frame_right.columnconfigure((0, 1), weight=1)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.frame_right.columnconfigure(2, weight=0)
|
2022-02-23 03:47:34 +03:00
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
self.frame_info = customtkinter.CTkFrame(master=self.frame_right)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.frame_info.grid(row=0, column=0, columnspan=2, rowspan=4, pady=20, padx=20, sticky="nsew")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-04-18 00:51:33 +03:00
|
|
|
# ============ frame_info ============
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-04-18 00:51:33 +03:00
|
|
|
# configure grid layout (1x1)
|
2022-03-05 04:01:07 +03:00
|
|
|
self.frame_info.rowconfigure(0, weight=1)
|
|
|
|
self.frame_info.columnconfigure(0, weight=1)
|
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
self.label_info_1 = customtkinter.CTkLabel(master=self.frame_info,
|
|
|
|
text="CTkLabel: Lorem ipsum dolor sit,\n" +
|
|
|
|
"amet consetetur sadipscing elitr,\n" +
|
2022-03-08 19:33:51 +03:00
|
|
|
"sed diam nonumy eirmod tempor" ,
|
2021-03-05 22:27:34 +03:00
|
|
|
height=100,
|
|
|
|
fg_color=("white", "gray38"), # <- custom tuple-color
|
|
|
|
justify=tkinter.LEFT)
|
2022-03-05 04:01:07 +03:00
|
|
|
self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15)
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-05 15:05:39 +03:00
|
|
|
self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info)
|
2022-03-05 04:01:07 +03:00
|
|
|
self.progressbar.grid(row=1, column=0, sticky="ew", padx=15, pady=15)
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-04-18 00:51:33 +03:00
|
|
|
# ============ frame_right ============
|
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
self.radio_var = tkinter.IntVar(value=0)
|
|
|
|
|
|
|
|
self.label_radio_group = customtkinter.CTkLabel(master=self.frame_right,
|
|
|
|
text="CTkRadioButton Group:")
|
2022-03-08 19:33:51 +03:00
|
|
|
self.label_radio_group.grid(row=0, column=2, columnspan=1, pady=20, padx=10, sticky="")
|
2022-03-05 04:01:07 +03:00
|
|
|
|
|
|
|
self.radio_button_1 = customtkinter.CTkRadioButton(master=self.frame_right,
|
2022-03-05 15:05:39 +03:00
|
|
|
variable=self.radio_var,
|
|
|
|
value=0)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.radio_button_1.grid(row=1, column=2, pady=10, padx=20, sticky="n")
|
2022-03-05 04:01:07 +03:00
|
|
|
|
|
|
|
self.radio_button_2 = customtkinter.CTkRadioButton(master=self.frame_right,
|
|
|
|
variable=self.radio_var,
|
|
|
|
value=1)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.radio_button_2.grid(row=2, column=2, pady=10, padx=20, sticky="n")
|
2022-03-05 04:01:07 +03:00
|
|
|
|
|
|
|
self.radio_button_3 = customtkinter.CTkRadioButton(master=self.frame_right,
|
|
|
|
variable=self.radio_var,
|
|
|
|
value=2)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="n")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
|
|
|
self.slider_1 = customtkinter.CTkSlider(master=self.frame_right,
|
2022-03-08 19:33:51 +03:00
|
|
|
from_=0,
|
|
|
|
to=1,
|
2021-12-20 13:55:07 +03:00
|
|
|
number_of_steps=3,
|
2021-11-11 00:17:49 +03:00
|
|
|
command=self.progressbar.set)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.slider_1.grid(row=4, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
|
|
|
self.slider_2 = customtkinter.CTkSlider(master=self.frame_right,
|
2021-11-11 00:17:49 +03:00
|
|
|
command=self.progressbar.set)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.slider_2.grid(row=5, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
self.slider_button_1 = customtkinter.CTkButton(master=self.frame_right,
|
2022-03-05 15:05:39 +03:00
|
|
|
height=25,
|
|
|
|
text="CTkButton",
|
|
|
|
command=self.button_event)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.slider_button_1.grid(row=4, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-05 04:01:07 +03:00
|
|
|
self.slider_button_2 = customtkinter.CTkButton(master=self.frame_right,
|
2022-03-05 15:05:39 +03:00
|
|
|
height=25,
|
|
|
|
text="CTkButton",
|
|
|
|
command=self.button_event)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.slider_button_2.grid(row=5, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
|
|
|
|
|
|
|
self.checkbox_button_1 = customtkinter.CTkButton(master=self.frame_right,
|
|
|
|
height=25,
|
|
|
|
text="CTkButton",
|
|
|
|
border_width=3, # <- custom border_width
|
|
|
|
fg_color=None, # <- no fg_color
|
|
|
|
command=self.button_event)
|
|
|
|
self.checkbox_button_1.grid(row=6, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
|
|
|
|
|
|
|
self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_right,
|
|
|
|
text="CTkCheckBox")
|
|
|
|
self.check_box_1.grid(row=6, column=0, pady=10, padx=20, sticky="w")
|
|
|
|
|
|
|
|
self.check_box_2 = customtkinter.CTkCheckBox(master=self.frame_right,
|
|
|
|
text="CTkCheckBox")
|
|
|
|
self.check_box_2.grid(row=6, column=1, pady=10, padx=20, sticky="w")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
|
|
|
self.entry = customtkinter.CTkEntry(master=self.frame_right,
|
|
|
|
width=120,
|
2022-02-08 22:59:50 +03:00
|
|
|
placeholder_text="CTkEntry")
|
2022-03-08 19:33:51 +03:00
|
|
|
self.entry.grid(row=8, column=0, columnspan=2, pady=20, padx=20, sticky="we")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
|
|
|
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
|
|
|
|
text="CTkButton",
|
2022-03-02 02:53:58 +03:00
|
|
|
command=self.button_event)
|
2022-03-08 19:33:51 +03:00
|
|
|
self.button_5.grid(row=8, column=2, columnspan=1, pady=20, padx=20, sticky="we")
|
2021-03-05 22:27:34 +03:00
|
|
|
|
2022-03-08 19:33:51 +03:00
|
|
|
# set default values
|
|
|
|
self.radio_button_1.select()
|
|
|
|
self.switch_2.select()
|
|
|
|
self.slider_1.set(0.2)
|
|
|
|
self.slider_2.set(0.7)
|
2022-03-01 18:12:55 +03:00
|
|
|
self.progressbar.set(0.5)
|
2022-03-10 04:12:30 +03:00
|
|
|
self.slider_button_1.configure(state=tkinter.DISABLED, text="Disabled Button")
|
|
|
|
self.radio_button_3.configure(state=tkinter.DISABLED)
|
|
|
|
self.check_box_1.configure(state=tkinter.DISABLED, text="CheckBox disabled")
|
2022-03-09 23:32:27 +03:00
|
|
|
self.check_box_2.select()
|
2022-02-28 02:35:52 +03:00
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
def button_event(self):
|
|
|
|
print("Button pressed")
|
|
|
|
|
2022-02-21 17:35:08 +03:00
|
|
|
def change_mode(self):
|
2022-03-08 19:33:51 +03:00
|
|
|
if self.switch_2.get() == 1:
|
2022-02-21 17:35:08 +03:00
|
|
|
customtkinter.set_appearance_mode("dark")
|
|
|
|
else:
|
|
|
|
customtkinter.set_appearance_mode("light")
|
|
|
|
|
2021-03-05 22:27:34 +03:00
|
|
|
def on_closing(self, event=0):
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.mainloop()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = App()
|
|
|
|
app.start()
|