mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
updatet complex_example.py with switches
This commit is contained in:
parent
3285eba2ef
commit
2ab5b7e19f
@ -3,7 +3,7 @@
|
||||
"window_bg_color": ["gray92", "gray12"],
|
||||
"button": ["#1FA6E8", "#1C94CF"],
|
||||
"button_hover": ["#1A89BF", "#1673A1"],
|
||||
"button_border": ["gray25", "gray86"],
|
||||
"button_border": ["gray40", "gray70"],
|
||||
"checkbox_border": ["gray40", "gray60"],
|
||||
"entry": ["white", "gray24"],
|
||||
"entry_border": ["gray70", "gray32"],
|
||||
@ -22,7 +22,7 @@
|
||||
"slider_button_hover": ["#1A89BF", "#1673A1"],
|
||||
"switch": ["gray70", "gray35"],
|
||||
"switch_progress": ["#1FA6E8", "#1C94CF"],
|
||||
"switch_button": ["gray38", "gray70"],
|
||||
"switch_button": ["gray36", "gray75"],
|
||||
"switch_button_hover": ["gray30", "gray90"],
|
||||
"darken_factor": 0.8
|
||||
},
|
||||
|
@ -1,16 +1,16 @@
|
||||
{
|
||||
"color": {
|
||||
"window_bg_color": ["gray94", "gray10"],
|
||||
"window_bg_color": ["gray98", "gray10"],
|
||||
"button": ["#608BD5", "#395E9C"],
|
||||
"button_hover": ["#A4BDE6", "#748BB3"],
|
||||
"button_border": ["gray25", "gray86"],
|
||||
"button_border": ["gray40", "gray70"],
|
||||
"checkbox_border": ["gray40", "gray60"],
|
||||
"entry": ["white", "gray24"],
|
||||
"entry_border": ["gray70", "gray32"],
|
||||
"entry_placeholder_text": ["gray52", "gray62"],
|
||||
"frame_border": ["#A7C2E0", "#5FB4DD"],
|
||||
"frame_low": ["gray89", "gray16"],
|
||||
"frame_high": ["gray84", "gray20"],
|
||||
"frame_low": ["gray92", "gray16"],
|
||||
"frame_high": ["gray86", "gray20"],
|
||||
"label": [null, null],
|
||||
"text": ["gray12", "gray90"],
|
||||
"progressbar": ["#6B6B6B", "gray6"],
|
||||
|
@ -4,7 +4,7 @@
|
||||
"window_bg_color": ["gray92", "gray12"],
|
||||
"button": ["#72CF9F", "#11B384"],
|
||||
"button_hover": ["#0E9670", "#0D8A66"],
|
||||
"button_border": ["gray25", "gray86"],
|
||||
"button_border": ["gray40", "gray70"],
|
||||
"checkbox_border": ["gray40", "gray60"],
|
||||
"entry": ["white", "gray24"],
|
||||
"entry_border": ["gray70", "gray32"],
|
||||
|
@ -109,7 +109,7 @@ class CTkLabel(tkinter.Frame):
|
||||
self.width = event.width
|
||||
self.height = event.height
|
||||
|
||||
self.canvas.config(width=self.width, height=self.height)
|
||||
# self.canvas.config(width=self.width, height=self.height)
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
|
@ -20,7 +20,7 @@ class CTkSettings:
|
||||
9: 'D', 8: 'D', 7: 'D', 6: 'F', 5: 'D', 4: 'G', 3: 'G', 2: 'H', 1: 'H', 0: 'A'}
|
||||
|
||||
radius_to_char_fine_windows_11 = {19: 'A', 18: 'A', 17: 'B', 16: 'B', 15: 'B', 14: 'B', 13: 'C', 12: 'C', 11: 'D', 10: 'D',
|
||||
9: 'D', 8: 'F', 7: 'C', 6: 'I', 5: 'E', 4: 'G', 3: 'P', 2: 'R', 1: 'R', 0: 'A'}
|
||||
9: 'E', 8: 'F', 7: 'C', 6: 'I', 5: 'E', 4: 'G', 3: 'P', 2: 'R', 1: 'R', 0: 'A'}
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
if sys.getwindowsversion().build > 20000: # Windows 11
|
||||
|
@ -238,6 +238,9 @@ class CTkSwitch(tkinter.Frame):
|
||||
self.variable.set(self.offvalue)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
def get(self):
|
||||
return self.onvalue if self.check_state is True else self.offvalue
|
||||
|
||||
def on_enter(self, event=0):
|
||||
self.hover_state = True
|
||||
self.canvas.itemconfig("slider_parts", fill=CTkThemeManager.single_color(self.button_hover_color, self.appearance_mode),
|
||||
|
@ -3,21 +3,21 @@ import tkinter.messagebox
|
||||
import customtkinter
|
||||
import sys
|
||||
|
||||
customtkinter.set_appearance_mode("Dark") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("dark-blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
WIDTH = 750
|
||||
HEIGHT = 500
|
||||
WIDTH = 780
|
||||
HEIGHT = 520
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.title("CustomTkinter complex example")
|
||||
self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
|
||||
self.minsize(App.WIDTH, App.HEIGHT)
|
||||
# self.minsize(App.WIDTH, App.HEIGHT)
|
||||
|
||||
self.protocol("WM_DELETE_WINDOW", self.on_closing)
|
||||
if sys.platform == "darwin":
|
||||
@ -27,6 +27,10 @@ class App(customtkinter.CTk):
|
||||
|
||||
# ============ create two frames ============
|
||||
|
||||
# configure grid layout (1x2)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
|
||||
self.frame_left = customtkinter.CTkFrame(master=self,
|
||||
width=180,
|
||||
corner_radius=0)
|
||||
@ -35,14 +39,13 @@ class App(customtkinter.CTk):
|
||||
self.frame_right = customtkinter.CTkFrame(master=self)
|
||||
self.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)
|
||||
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
|
||||
# ============ frame_left ============
|
||||
|
||||
self.frame_left.grid_rowconfigure(0, minsize=10)
|
||||
self.frame_left.grid_rowconfigure(5, weight=1)
|
||||
self.frame_left.grid_rowconfigure(8, minsize=10)
|
||||
# configure grid layout
|
||||
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
|
||||
|
||||
self.label_1 = customtkinter.CTkLabel(master=self.frame_left,
|
||||
text="CustomTkinter",
|
||||
@ -51,41 +54,42 @@ class App(customtkinter.CTk):
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(master=self.frame_left,
|
||||
text="CTkButton 1",
|
||||
command=self.button_event,
|
||||
fg_color=("gray75", "gray30")) # <- custom tuple-color
|
||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
||||
command=self.button_event)
|
||||
self.button_1.grid(row=2, column=0, pady=10, padx=20)
|
||||
|
||||
self.button_2 = customtkinter.CTkButton(master=self.frame_left,
|
||||
text="CTkButton 2",
|
||||
command=self.button_event,
|
||||
fg_color=("gray75", "gray30")) # <- custom tuple-color
|
||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
||||
command=self.button_event)
|
||||
self.button_2.grid(row=3, column=0, pady=10, padx=20)
|
||||
|
||||
self.button_3 = customtkinter.CTkButton(master=self.frame_left,
|
||||
text="CTkButton 3",
|
||||
command=self.button_event,
|
||||
fg_color=("gray75", "gray30")) # <- custom tuple-color
|
||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
||||
command=self.button_event)
|
||||
self.button_3.grid(row=4, column=0, pady=10, padx=20)
|
||||
|
||||
self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_left,
|
||||
text="CTkCheckBox")
|
||||
self.check_box_1.grid(row=6, column=0, pady=10, padx=20, sticky="w")
|
||||
self.switch_1 = customtkinter.CTkSwitch(master=self.frame_left)
|
||||
self.switch_1.grid(row=9, column=0, pady=10, padx=20, sticky="w")
|
||||
|
||||
self.check_box_2 = customtkinter.CTkCheckBox(master=self.frame_left,
|
||||
self.switch_2 = customtkinter.CTkSwitch(master=self.frame_left,
|
||||
text="Dark Mode",
|
||||
command=self.change_mode)
|
||||
self.check_box_2.grid(row=7, column=0, pady=10, padx=20, sticky="w")
|
||||
self.switch_2.grid(row=10, column=0, pady=10, padx=20, sticky="w")
|
||||
|
||||
# ============ frame_right ============
|
||||
|
||||
# configure grid layout (3x7)
|
||||
for i in [0, 1, 2, 3]:
|
||||
self.frame_right.rowconfigure(i, weight=1)
|
||||
self.frame_right.rowconfigure(6, weight=10)
|
||||
self.frame_right.rowconfigure(7, weight=10)
|
||||
self.frame_right.columnconfigure(0, weight=1)
|
||||
self.frame_right.columnconfigure(1, weight=0)
|
||||
self.frame_right.columnconfigure(1, weight=1)
|
||||
self.frame_right.columnconfigure(2, weight=0)
|
||||
|
||||
self.frame_info = customtkinter.CTkFrame(master=self.frame_right)
|
||||
self.frame_info.grid(row=0, column=0, columnspan=1, rowspan=4, pady=20, padx=20, sticky="nsew")
|
||||
self.frame_info.grid(row=0, column=0, columnspan=2, rowspan=4, pady=20, padx=20, sticky="nsew")
|
||||
|
||||
# ============ frame_right -> frame_info ============
|
||||
|
||||
@ -95,8 +99,7 @@ class App(customtkinter.CTk):
|
||||
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",
|
||||
"sed diam nonumy eirmod tempor" ,
|
||||
height=100,
|
||||
fg_color=("white", "gray38"), # <- custom tuple-color
|
||||
justify=tkinter.LEFT)
|
||||
@ -110,68 +113,84 @@ class App(customtkinter.CTk):
|
||||
|
||||
self.label_radio_group = customtkinter.CTkLabel(master=self.frame_right,
|
||||
text="CTkRadioButton Group:")
|
||||
self.label_radio_group.grid(row=0, column=1, columnspan=1, pady=20, padx=10, sticky="")
|
||||
self.label_radio_group.grid(row=0, column=2, columnspan=1, pady=20, padx=10, sticky="")
|
||||
|
||||
self.radio_button_1 = customtkinter.CTkRadioButton(master=self.frame_right,
|
||||
variable=self.radio_var,
|
||||
value=0)
|
||||
self.radio_button_1.grid(row=1, column=1, pady=10, padx=20, sticky="n")
|
||||
self.radio_button_1.grid(row=1, column=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
self.radio_button_2 = customtkinter.CTkRadioButton(master=self.frame_right,
|
||||
variable=self.radio_var,
|
||||
value=1)
|
||||
self.radio_button_2.grid(row=2, column=1, pady=10, padx=20, sticky="n")
|
||||
self.radio_button_2.grid(row=2, column=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
self.radio_button_3 = customtkinter.CTkRadioButton(master=self.frame_right,
|
||||
variable=self.radio_var,
|
||||
value=2)
|
||||
self.radio_button_3.grid(row=3, column=1, pady=10, padx=20, sticky="n")
|
||||
|
||||
#self.radio_button_1.select()
|
||||
#self.radio_button_1.deselect()
|
||||
self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
self.slider_1 = customtkinter.CTkSlider(master=self.frame_right,
|
||||
from_=1,
|
||||
to=0,
|
||||
from_=0,
|
||||
to=1,
|
||||
number_of_steps=3,
|
||||
command=self.progressbar.set)
|
||||
self.slider_1.grid(row=4, column=0, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
self.slider_1.set(0.7)
|
||||
self.slider_1.grid(row=4, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
||||
|
||||
self.slider_2 = customtkinter.CTkSlider(master=self.frame_right,
|
||||
command=self.progressbar.set)
|
||||
self.slider_2.grid(row=5, column=0, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
self.slider_2.set(0.7)
|
||||
self.slider_2.grid(row=5, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
||||
|
||||
self.slider_button_1 = customtkinter.CTkButton(master=self.frame_right,
|
||||
height=25,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.slider_button_1.grid(row=4, column=1, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
self.slider_button_1.grid(row=4, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
|
||||
self.slider_button_2 = customtkinter.CTkButton(master=self.frame_right,
|
||||
height=25,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.slider_button_2.grid(row=5, column=1, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
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")
|
||||
|
||||
self.entry = customtkinter.CTkEntry(master=self.frame_right,
|
||||
width=120,
|
||||
placeholder_text="CTkEntry")
|
||||
self.entry.grid(row=7, column=0, columnspan=1, pady=20, padx=20, sticky="we")
|
||||
self.entry.grid(row=8, column=0, columnspan=2, pady=20, padx=20, sticky="we")
|
||||
|
||||
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.button_5.grid(row=7, column=1, columnspan=1, pady=20, padx=20, sticky="we")
|
||||
self.button_5.grid(row=8, column=2, columnspan=1, pady=20, padx=20, sticky="we")
|
||||
|
||||
# set default values
|
||||
self.radio_button_1.select()
|
||||
self.switch_2.select()
|
||||
self.slider_1.set(0.2)
|
||||
self.slider_2.set(0.7)
|
||||
self.progressbar.set(0.5)
|
||||
|
||||
def button_event(self):
|
||||
print("Button pressed")
|
||||
|
||||
def change_mode(self):
|
||||
if self.check_box_2.get() == 1:
|
||||
if self.switch_2.get() == 1:
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
else:
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
@ -1,8 +1,8 @@
|
||||
import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
|
||||
customtkinter.set_appearance_mode("Dark") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("green") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
||||
root_tk.geometry("400x480")
|
||||
|
Loading…
Reference in New Issue
Block a user