CustomTkinter/examples/complex_example_other_style.py

182 lines
8.8 KiB
Python
Raw Normal View History

2021-03-05 23:05:53 +03:00
import tkinter
import tkinter.messagebox
import customtkinter
2021-03-06 00:14:47 +03:00
import sys
2021-03-05 23:05:53 +03:00
2021-03-06 00:14:47 +03:00
# Set dark appearance mode:
2021-03-06 00:08:50 +03:00
customtkinter.set_appearance_mode("Dark") # Other: "Light", "System"
2021-03-05 23:05:53 +03:00
class App(customtkinter.CTk):
2021-03-05 23:05:53 +03:00
APP_NAME = "CustomTkinter complex example"
WIDTH = 700
HEIGHT = 500
MAIN_COLOR = "#5EA880"
MAIN_COLOR_DARK = "#2D5862"
MAIN_HOVER = "#458577"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2021-03-06 00:14:47 +03:00
2021-03-05 23:05:53 +03:00
self.title(App.APP_NAME)
self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
self.minsize(App.WIDTH, App.HEIGHT)
self.protocol("WM_DELETE_WINDOW", self.on_closing)
if sys.platform == "darwin":
self.bind("<Command-q>", self.on_closing)
self.bind("<Command-w>", self.on_closing)
self.createcommand('tk::mac::Quit', self.on_closing)
2021-03-05 23:05:53 +03:00
# ============ create two CTkFrames ============
self.frame_left = customtkinter.CTkFrame(master=self,
width=200,
height=App.HEIGHT-40,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.frame_left.place(relx=0.32, rely=0.5, anchor=tkinter.E)
self.frame_right = customtkinter.CTkFrame(master=self,
width=420,
height=App.HEIGHT-40,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.frame_right.place(relx=0.365, rely=0.5, anchor=tkinter.W)
# ============ frame_left ============
self.button_1 = customtkinter.CTkButton(master=self.frame_left,
border_color=App.MAIN_COLOR,
fg_color=None,
hover_color=App.MAIN_HOVER,
text="CTkButton",
command=self.button_event,
border_width=3,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.button_1.place(relx=0.5, y=50, anchor=tkinter.CENTER)
self.button_2 = customtkinter.CTkButton(master=self.frame_left,
border_color=App.MAIN_COLOR,
fg_color=None,
hover_color=App.MAIN_HOVER,
text="CTkButton",
command=self.button_event,
border_width=3,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.button_2.place(relx=0.5, y=100, anchor=tkinter.CENTER)
self.button_3 = customtkinter.CTkButton(master=self.frame_left,
border_color=App.MAIN_COLOR,
fg_color=None,
hover_color=App.MAIN_HOVER,
text="CTkButton",
command=self.button_event,
border_width=3,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.button_3.place(relx=0.5, y=150, anchor=tkinter.CENTER)
# ============ frame_right ============
self.frame_info = customtkinter.CTkFrame(master=self.frame_right,
width=380,
height=200,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.frame_info.place(relx=0.5, y=20, anchor=tkinter.N)
# ============ frame_right -> frame_info ============
self.label_info_1 = customtkinter.CTkLabel(master=self.frame_info,
text="CTkLabel: Lorem ipsum dolor sit,\n" +
"amet consetetur sadipscing elitr,\n" +
"sed diam nonumy eirmod tempor\n" +
"invidunt ut labore",
width=250,
height=100,
corner_radius=5,
2021-03-05 23:05:53 +03:00
fg_color=("white", "gray20"),
text_color=App.MAIN_COLOR,
justify=tkinter.LEFT)
self.label_info_1.place(relx=0.5, rely=0.15, anchor=tkinter.N)
self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info,
progress_color=App.MAIN_COLOR,
width=250,
height=12)
2021-03-05 23:05:53 +03:00
self.progressbar.place(relx=0.5, rely=0.85, anchor=tkinter.S)
2021-03-12 14:15:38 +03:00
self.progressbar.set(0.65)
2021-03-05 23:05:53 +03:00
# ============ frame_right <- ============
self.slider_1 = customtkinter.CTkSlider(master=self.frame_right,
button_color=App.MAIN_COLOR,
button_hover_color=App.MAIN_HOVER,
width=160,
height=16,
number_of_steps=3,
border_width=5,
command=self.progressbar.set)
2021-03-05 23:05:53 +03:00
self.slider_1.place(x=20, rely=0.6, anchor=tkinter.W)
self.slider_1.set(0.3)
self.slider_2 = customtkinter.CTkSlider(master=self.frame_right,
button_color=App.MAIN_COLOR,
button_hover_color=App.MAIN_HOVER,
width=160,
height=16,
border_width=5,
command=self.progressbar.set)
2021-03-05 23:05:53 +03:00
self.slider_2.place(x=20, rely=0.7, anchor=tkinter.W)
self.slider_2.set(0.7)
2021-03-06 00:03:31 +03:00
self.label_info_2 = customtkinter.CTkLabel(master=self.frame_right,
2021-03-05 23:05:53 +03:00
text="CTkLabel: Lorem ipsum",
2022-01-08 02:29:53 +03:00
fg_color=None,
2021-03-06 00:03:31 +03:00
width=180,
2021-03-05 23:05:53 +03:00
height=20,
justify=tkinter.CENTER)
2021-03-06 00:03:31 +03:00
self.label_info_2.place(x=310, rely=0.6, anchor=tkinter.CENTER)
2021-03-05 23:05:53 +03:00
self.button_4 = customtkinter.CTkButton(master=self.frame_right,
border_color=App.MAIN_COLOR,
fg_color=None,
hover_color=App.MAIN_HOVER,
2021-03-12 14:15:38 +03:00
height=28,
2021-03-05 23:05:53 +03:00
text="CTkButton",
command=self.button_event,
border_width=3,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.button_4.place(x=310, rely=0.7, anchor=tkinter.CENTER)
self.entry = customtkinter.CTkEntry(master=self.frame_right,
width=120,
2021-03-12 14:15:38 +03:00
height=28,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.entry.place(relx=0.33, rely=0.92, anchor=tkinter.CENTER)
self.entry.insert(0, "CTkEntry")
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
border_color=App.MAIN_COLOR,
fg_color=None,
hover_color=App.MAIN_HOVER,
2021-03-12 14:15:38 +03:00
height=28,
2021-03-05 23:05:53 +03:00
text="CTkButton",
command=self.button_event,
border_width=3,
corner_radius=5)
2021-03-05 23:05:53 +03:00
self.button_5.place(relx=0.66, rely=0.92, anchor=tkinter.CENTER)
def button_event(self):
print("Button pressed")
def on_closing(self, event=0):
self.destroy()
def start(self):
self.mainloop()
if __name__ == "__main__":
app = App()
app.start()