mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
fixed small scaling issues
This commit is contained in:
179
test/visual_tests/test_all_widgets_with_colors.py
Normal file
179
test/visual_tests/test_all_widgets_with_colors.py
Normal file
@ -0,0 +1,179 @@
|
||||
import tkinter
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("green") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
|
||||
class TestApp(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.geometry(f"{1400}x{700}")
|
||||
self.title("CustomTkinter complete test")
|
||||
|
||||
self.create_widgets_on_tk()
|
||||
self.create_widgets_on_ctk_frame()
|
||||
self.create_widgets_on_ctk_frame_customized()
|
||||
self.create_widgets_on_tk_frame_customized()
|
||||
|
||||
def change_appearance_mode(self, value):
|
||||
""" gets called by self.slider_1 """
|
||||
|
||||
if value == 0:
|
||||
self.label_1.set_text("mode: Light")
|
||||
customtkinter.set_appearance_mode("Light")
|
||||
elif value == 1:
|
||||
self.label_1.set_text("mode: Dark")
|
||||
customtkinter.set_appearance_mode("Dark")
|
||||
else:
|
||||
self.label_1.set_text("mode: System")
|
||||
customtkinter.set_appearance_mode("System")
|
||||
|
||||
def create_widgets_on_tk(self):
|
||||
x, y = 150, 80
|
||||
|
||||
self.label_1 = customtkinter.CTkLabel(master=self, text="widgets_on_tk", fg_color="gray50")
|
||||
self.label_1.place(x=x, y=y, anchor=tkinter.CENTER)
|
||||
|
||||
self.frame_1 = customtkinter.CTkFrame(master=self, width=200, height=60)
|
||||
self.frame_1.place(x=x, y=y+80, anchor=tkinter.CENTER)
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(master=self)
|
||||
self.button_1.place(x=x, y=y + 160, anchor=tkinter.CENTER)
|
||||
|
||||
self.entry_1 = customtkinter.CTkEntry(master=self)
|
||||
self.entry_1.place(x=x, y=y + 240, anchor=tkinter.CENTER)
|
||||
|
||||
self.progress_bar_1 = customtkinter.CTkProgressBar(master=self)
|
||||
self.progress_bar_1.place(x=x, y=y + 320, anchor=tkinter.CENTER)
|
||||
|
||||
self.slider_1 = customtkinter.CTkSlider(master=self, command=self.change_appearance_mode, from_=0, to=2, number_of_steps=2)
|
||||
self.slider_1.place(x=x, y=y + 400, anchor=tkinter.CENTER)
|
||||
|
||||
self.check_box_1 = customtkinter.CTkCheckBox(master=self)
|
||||
self.check_box_1.place(x=x, y=y + 480, anchor=tkinter.CENTER)
|
||||
|
||||
def create_widgets_on_ctk_frame(self):
|
||||
x, y = 450, 40
|
||||
|
||||
self.ctk_frame = customtkinter.CTkFrame(master=self, width=300, height=600)
|
||||
self.ctk_frame.place(x=x, y=y, anchor=tkinter.N)
|
||||
|
||||
self.label_2 = customtkinter.CTkLabel(master=self.ctk_frame, text="create_widgets_on_ctk_frame", fg_color="gray50", width=200)
|
||||
self.label_2.place(relx=0.5, y=y, anchor=tkinter.CENTER)
|
||||
|
||||
self.frame_2 = customtkinter.CTkFrame(master=self.ctk_frame, width=200, height=60)
|
||||
self.frame_2.place(relx=0.5, y=y + 80, anchor=tkinter.CENTER)
|
||||
|
||||
self.button_2 = customtkinter.CTkButton(master=self.ctk_frame, border_width=3)
|
||||
self.button_2.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)
|
||||
|
||||
self.entry_2 = customtkinter.CTkEntry(master=self.ctk_frame)
|
||||
self.entry_2.place(relx=0.5, y=y + 240, anchor=tkinter.CENTER)
|
||||
|
||||
self.progress_bar_2 = customtkinter.CTkProgressBar(master=self.ctk_frame)
|
||||
self.progress_bar_2.place(relx=0.5, y=y + 320, anchor=tkinter.CENTER)
|
||||
|
||||
self.slider_2 = customtkinter.CTkSlider(master=self.ctk_frame, command=lambda v: self.label_2.set_text(str(round(v, 5))))
|
||||
self.slider_2.place(relx=0.5, y=y + 400, anchor=tkinter.CENTER)
|
||||
|
||||
self.check_box_2 = customtkinter.CTkCheckBox(master=self.ctk_frame)
|
||||
self.check_box_2.place(relx=0.5, y=y + 480, anchor=tkinter.CENTER)
|
||||
|
||||
def change_frame_color(self, value):
|
||||
""" gets called by self.slider_3 """
|
||||
|
||||
def rgb2hex(rgb_color: tuple) -> str:
|
||||
return "#{:02x}{:02x}{:02x}".format(round(rgb_color[0]), round(rgb_color[1]), round(rgb_color[2]))
|
||||
|
||||
col_1 = rgb2hex((100, 50, value * 250))
|
||||
col_2 = rgb2hex((20, value * 250, 50))
|
||||
|
||||
self.ctk_frame_customized.configure(fg_color=col_1)
|
||||
self.tk_frame_customized.configure(bg=col_1)
|
||||
self.configure(bg=col_2)
|
||||
self.progress_bar_3.set(value)
|
||||
|
||||
def create_widgets_on_ctk_frame_customized(self):
|
||||
x, y = 800, 40
|
||||
|
||||
self.ctk_frame_customized = customtkinter.CTkFrame(master=self, width=300, height=600)
|
||||
self.ctk_frame_customized.place(x=x, y=y, anchor=tkinter.N)
|
||||
self.ctk_frame_customized.configure(fg_color=("#F4F4FA", "#1E2742"))
|
||||
|
||||
self.label_3 = customtkinter.CTkLabel(master=self.ctk_frame_customized, text="customized", corner_radius=60,
|
||||
text_font=("times", 16))
|
||||
self.label_3.place(relx=0.5, y=y, anchor=tkinter.CENTER)
|
||||
self.label_3.configure(fg_color=("#F4F4FA", "#333D5E"), text_color=("#373E57", "#7992C1"))
|
||||
|
||||
self.frame_3 = customtkinter.CTkFrame(master=self.ctk_frame_customized, width=200, height=60)
|
||||
self.frame_3.place(relx=0.5, y=y + 80, anchor=tkinter.CENTER)
|
||||
self.frame_3.configure(fg_color=("#EBECF3", "#4B577E"))
|
||||
|
||||
self.button_3 = customtkinter.CTkButton(master=self.ctk_frame_customized, command=lambda: x, border_width=3,
|
||||
corner_radius=20, text_font=("times", 16))
|
||||
self.button_3.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)
|
||||
self.button_3.configure(border_color=("#4F90F8", "#6FADF9"), hover_color=("#3A65E8", "#4376EE"))
|
||||
self.button_3.configure(fg_color=None)
|
||||
|
||||
self.entry_3 = customtkinter.CTkEntry(master=self.ctk_frame_customized, text_font=("times", 16))
|
||||
self.entry_3.place(relx=0.5, y=y + 240, anchor=tkinter.CENTER)
|
||||
self.entry_3.configure(fg_color=("gray60", "gray5"), corner_radius=20)
|
||||
self.entry_3.insert(0, "1234567890")
|
||||
self.entry_3.focus_set()
|
||||
|
||||
self.progress_bar_3 = customtkinter.CTkProgressBar(master=self.ctk_frame_customized, height=16, fg_color=("#EBECF3", "#4B577E"))
|
||||
self.progress_bar_3.place(relx=0.5, y=y + 320, anchor=tkinter.CENTER)
|
||||
self.progress_bar_3.configure(progress_color="#8AE0C3", border_width=3, border_color=("gray60", "#4B577E"))
|
||||
|
||||
self.slider_3 = customtkinter.CTkSlider(master=self.ctk_frame_customized, command=self.change_frame_color, from_=0, to=10)
|
||||
self.slider_3.place(relx=0.5, y=y + 400, anchor=tkinter.CENTER)
|
||||
self.slider_3.configure(button_color="#8AE0C3", fg_color=("#EBECF3", "#4B577E"), progress_color=("gray30", "gray10"))
|
||||
self.slider_3.configure(from_=0, to=1)
|
||||
|
||||
self.check_box_3 = customtkinter.CTkCheckBox(master=self.ctk_frame_customized, corner_radius=50, text_font=("times", 16))
|
||||
self.check_box_3.place(relx=0.5, y=y + 480, anchor=tkinter.CENTER)
|
||||
self.check_box_3.configure(border_color="#8AE0C3")
|
||||
|
||||
def create_widgets_on_tk_frame_customized(self):
|
||||
x, y = 1150, 40
|
||||
|
||||
self.tk_frame_customized = tkinter.Frame(master=self, width=300, height=600, bg="darkred")
|
||||
self.tk_frame_customized.place(x=x, y=y, anchor=tkinter.N)
|
||||
|
||||
self.label_4 = customtkinter.CTkLabel(master=self.tk_frame_customized, text="customized", corner_radius=6)
|
||||
self.label_4.place(relx=0.5, y=y, anchor=tkinter.CENTER)
|
||||
self.label_4.configure(fg_color=("#F4F4FA", "#333D5E"), text_color=("#373E57", "#7992C1"))
|
||||
|
||||
self.frame_4 = customtkinter.CTkFrame(master=self.tk_frame_customized, width=200, height=60)
|
||||
self.frame_4.place(relx=0.5, y=y + 80, anchor=tkinter.CENTER)
|
||||
self.frame_4.configure(fg_color=("#EBECF3", "#4B577E"))
|
||||
|
||||
self.button_4 = customtkinter.CTkButton(master=self.tk_frame_customized, command=lambda: x, border_width=3)
|
||||
self.button_4.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)
|
||||
self.button_4.configure(border_color=("#4F90F8", "#6FADF9"), hover_color=("#3A65E8", "#4376EE"))
|
||||
self.button_4.configure(fg_color=None)
|
||||
|
||||
self.entry_4 = customtkinter.CTkEntry(master=self.tk_frame_customized)
|
||||
self.entry_4.place(relx=0.5, y=y + 240, anchor=tkinter.CENTER)
|
||||
self.entry_4.configure(fg_color=("gray60", "gray5"))
|
||||
self.entry_4.insert(0, "1234567890")
|
||||
self.entry_4.focus_set()
|
||||
|
||||
self.progress_bar_4 = customtkinter.CTkProgressBar(master=self.tk_frame_customized, height=16, fg_color=("#EBECF3", "#4B577E"))
|
||||
self.progress_bar_4.place(relx=0.5, y=y + 320, anchor=tkinter.CENTER)
|
||||
self.progress_bar_4.configure(progress_color="#8AE0C3", border_width=3, border_color=("gray60", "#4B577E"))
|
||||
|
||||
self.slider_4 = customtkinter.CTkSlider(master=self.tk_frame_customized, command=self.change_frame_color, from_=0, to=10)
|
||||
self.slider_4.place(relx=0.5, y=y + 400, anchor=tkinter.CENTER)
|
||||
self.slider_4.configure(button_color="#8AE0C3", fg_color=("#EBECF3", "#4B577E"), progress_color=("gray30", "gray10"))
|
||||
self.slider_4.configure(from_=0, to=1)
|
||||
|
||||
self.check_box_4 = customtkinter.CTkCheckBox(master=self.tk_frame_customized)
|
||||
self.check_box_4.place(relx=0.5, y=y + 480, anchor=tkinter.CENTER)
|
||||
self.check_box_4.configure(border_color="#8AE0C3")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_app = TestApp()
|
||||
test_app.mainloop()
|
68
test/visual_tests/test_askdialog.py
Normal file
68
test/visual_tests/test_askdialog.py
Normal file
@ -0,0 +1,68 @@
|
||||
from tkinter.constants import CENTER, LEFT
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
from tkinter import filedialog as fd
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
import os
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
APP_NAME = "Bulk Barcode Generator"
|
||||
WIDTH = 600
|
||||
HEIGHT = 450
|
||||
|
||||
MAIN_COLOR = "#5ea886"
|
||||
MAIN_COLOR_DARK = "#2D5862"
|
||||
MAIN_HOVER = "#05f4b7"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
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)
|
||||
# ============ create two CTkFrames ============
|
||||
|
||||
self.frame_left = customtkinter.CTkFrame(master=self,
|
||||
width=220,
|
||||
height=App.HEIGHT-40,
|
||||
corner_radius=5)
|
||||
self.frame_left.place(relx=0.38, rely=0.5, anchor=tkinter.E)
|
||||
print(self.frame_left.widget_scaling)
|
||||
|
||||
self.frame_right = customtkinter.CTkFrame(master=self,
|
||||
width=350,
|
||||
height=App.HEIGHT-40,
|
||||
corner_radius=5)
|
||||
self.frame_right.place(relx=0.40, rely=0.5, anchor=tkinter.W)
|
||||
|
||||
# # ============ frame_right ============
|
||||
|
||||
self.button_output = customtkinter.CTkButton(master=self.frame_right, border_color=App.MAIN_COLOR,
|
||||
fg_color=None, hover_color=App.MAIN_HOVER,
|
||||
height=28, text="Output Folder", command=self.button_outputFunc,
|
||||
border_width=3, corner_radius=10, text_font=('Calibri',12))
|
||||
self.button_output.place(relx=0.05, rely=0.06, anchor=tkinter.NW)
|
||||
self.entry_output = customtkinter.CTkEntry(master=self.frame_right, width=320, height=38, corner_radius=5)
|
||||
self.entry_output.place(relx=0.05, rely=0.18, anchor=tkinter.NW)
|
||||
|
||||
def button_outputFunc(self):
|
||||
self.entry_output.delete(0, 'end')
|
||||
filename = fd.askdirectory()
|
||||
self.entry_output.insert(0,str(filename))
|
||||
pass
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
def start(self):
|
||||
self.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.start()
|
48
test/visual_tests/test_auto_resizing.py
Normal file
48
test/visual_tests/test_auto_resizing.py
Normal file
@ -0,0 +1,48 @@
|
||||
import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
from PIL import Image, ImageTk # <- import PIL for the images
|
||||
import os
|
||||
|
||||
PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
|
||||
|
||||
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("400x600")
|
||||
root_tk.title("CustomTkinter Test")
|
||||
|
||||
|
||||
def button_function():
|
||||
print("button pressed")
|
||||
|
||||
|
||||
# load images as PhotoImage
|
||||
settings_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/settings.png").resize((40, 40)))
|
||||
bell_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/bell.png").resize((40, 40)))
|
||||
|
||||
frame_1 = customtkinter.CTkFrame(master=root_tk, width=300, height=350)
|
||||
frame_1.place(relx=0.5, rely=0.5, relwidth=0.8, relheight=0.8, anchor=tkinter.CENTER)
|
||||
|
||||
# button with bell-image and standard compound ("left")
|
||||
button_2 = customtkinter.CTkButton(master=frame_1, height=60,
|
||||
corner_radius=10, command=button_function)
|
||||
button_2.place(relx=0.5, rely=0.3, relwidth=0.5, anchor=tkinter.CENTER)
|
||||
button_2.configure(image=bell_image)
|
||||
button_2.configure(image=settings_image, text="new text")
|
||||
|
||||
# button with settings-image and compound="right"
|
||||
button_3 = customtkinter.CTkButton(master=frame_1, text="large button 3", compound="right",
|
||||
command=button_function, height=30, corner_radius=8)
|
||||
button_3.place(relx=0.5, rely=0.5, relwidth=0.6, anchor=tkinter.CENTER)
|
||||
|
||||
entry_1 = customtkinter.CTkEntry(frame_1)
|
||||
entry_1.pack(fill="x", pady=10, padx=10)
|
||||
entry_1.configure(corner_radius=15)
|
||||
|
||||
label_1 = customtkinter.CTkLabel(frame_1, text="auto size label")
|
||||
label_1.place(relx=0.5, rely=0.85, anchor=tkinter.CENTER, relwidth=0.5, relheight=0.08)
|
||||
|
||||
entry_2 = customtkinter.CTkEntry(frame_1, corner_radius=6, height=30, width=90, justify='center')
|
||||
entry_2.place(relx=0.5, anchor=tkinter.CENTER, rely=0.15)
|
||||
|
||||
root_tk.mainloop()
|
50
test/visual_tests/test_button_antialiasing.py
Normal file
50
test/visual_tests/test_button_antialiasing.py
Normal file
@ -0,0 +1,50 @@
|
||||
import customtkinter
|
||||
import tkinter
|
||||
|
||||
customtkinter.set_default_color_theme("blue")
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("600x1000")
|
||||
|
||||
app.grid_columnconfigure(0, weight=1)
|
||||
app.grid_columnconfigure(1, weight=1)
|
||||
app.grid_columnconfigure(2, weight=1)
|
||||
app.grid_columnconfigure(3, weight=1)
|
||||
|
||||
f1 = customtkinter.CTkFrame(app, fg_color="gray10", corner_radius=0)
|
||||
f1.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="nsew")
|
||||
f1.grid_columnconfigure(0, weight=1)
|
||||
|
||||
f2 = customtkinter.CTkFrame(app, fg_color="gray10", corner_radius=0)
|
||||
f2.grid(row=0, column=1, rowspan=1, columnspan=1, sticky="nsew")
|
||||
f2.grid_columnconfigure(0, weight=1)
|
||||
|
||||
f3 = customtkinter.CTkFrame(app, fg_color="gray85", corner_radius=0)
|
||||
f3.grid(row=0, column=2, rowspan=1, columnspan=1, sticky="nsew")
|
||||
f3.grid_columnconfigure(0, weight=1)
|
||||
|
||||
f4 = customtkinter.CTkFrame(app, fg_color="gray90", corner_radius=0)
|
||||
f4.grid(row=0, column=3, rowspan=1, columnspan=1, sticky="nsew")
|
||||
f4.grid_columnconfigure(0, weight=1)
|
||||
|
||||
for i in range(0, 21, 1):
|
||||
#b = customtkinter.CTkButton(f1, corner_radius=i, current_height=34, border_width=2, text=f"{i} {i-2}",
|
||||
# border_color="white", fg_color=None, text_color="white")
|
||||
b = tkinter.Button(f1, text=f"{i} {i-2}", width=20)
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
b = customtkinter.CTkButton(f2, corner_radius=i, height=34, border_width=0, text=f"{i}",
|
||||
fg_color="#228da8")
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
b = customtkinter.CTkButton(f3, corner_radius=i, height=34, border_width=2, text=f"{i} {i-2}",
|
||||
fg_color=None, border_color="gray20", text_color="black")
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
b = customtkinter.CTkButton(f4, corner_radius=i, height=34, border_width=0, text=f"{i}",
|
||||
border_color="gray10", fg_color="#228da8")
|
||||
b.grid(row=i, column=0, pady=5, padx=15, sticky="nsew")
|
||||
|
||||
customtkinter.CTkSettings.print_settings()
|
||||
app.mainloop()
|
33
test/visual_tests/test_button_state.py
Normal file
33
test/visual_tests/test_button_state.py
Normal file
@ -0,0 +1,33 @@
|
||||
import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
|
||||
|
||||
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("400x240")
|
||||
root_tk.title("CustomTkinter Test")
|
||||
|
||||
|
||||
def change_button_2_state():
|
||||
if button_2.state == tkinter.NORMAL:
|
||||
button_2.configure(state=tkinter.DISABLED)
|
||||
elif button_2.state == tkinter.DISABLED:
|
||||
button_2.configure(state=tkinter.NORMAL)
|
||||
|
||||
|
||||
def button_2_click():
|
||||
print("button_2 clicked")
|
||||
|
||||
|
||||
frame_1 = customtkinter.CTkFrame(master=root_tk, width=300, height=200, corner_radius=15)
|
||||
frame_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=frame_1, text="Disable/Enable Button_2",
|
||||
corner_radius=10, command=change_button_2_state, width=200)
|
||||
button_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)
|
||||
|
||||
button_2 = customtkinter.CTkButton(master=frame_1, text="Button_2",
|
||||
corner_radius=10, command=button_2_click)
|
||||
button_2.place(relx=0.5, rely=0.7, anchor=tkinter.CENTER)
|
||||
|
||||
root_tk.mainloop()
|
25
test/visual_tests/test_ctk_toplevel.py
Normal file
25
test/visual_tests/test_ctk_toplevel.py
Normal file
@ -0,0 +1,25 @@
|
||||
import tkinter
|
||||
import customtkinter
|
||||
|
||||
|
||||
class ExampleApp(customtkinter.CTk):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.geometry("500x400")
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(self, text="Create CTkToplevel", command=self.create_toplevel)
|
||||
self.button_1.pack(side="top", padx=40, pady=40)
|
||||
|
||||
def create_toplevel(self):
|
||||
window = customtkinter.CTkToplevel(self)
|
||||
window.geometry("400x200")
|
||||
|
||||
print(window.master.winfo_class())
|
||||
|
||||
label = customtkinter.CTkLabel(window, text="CTkToplevel window")
|
||||
label.pack(side="top", fill="both", expand=True, padx=40, pady=40)
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
app.mainloop()
|
22
test/visual_tests/test_iconify_destroy.py
Normal file
22
test/visual_tests/test_iconify_destroy.py
Normal file
@ -0,0 +1,22 @@
|
||||
import tkinter
|
||||
import customtkinter
|
||||
|
||||
root_tk = customtkinter.CTk()
|
||||
root_tk.geometry("400x240")
|
||||
|
||||
|
||||
def button_function():
|
||||
|
||||
top = customtkinter.CTkToplevel(root_tk)
|
||||
|
||||
root_tk.after(1000, top.iconify) # hide toplevel
|
||||
root_tk.after(1500, top.deiconify) # show toplevel
|
||||
root_tk.after(2500, root_tk.iconify) # hide root_tk
|
||||
root_tk.after(3000, root_tk.deiconify) # show root_tk
|
||||
root_tk.after(4000, root_tk.destroy) # destroy everything
|
||||
|
||||
|
||||
button = customtkinter.CTkButton(root_tk, command=button_function)
|
||||
button.pack(pady=20, padx=20)
|
||||
|
||||
root_tk.mainloop()
|
BIN
test/visual_tests/test_images/bell.png
Normal file
BIN
test/visual_tests/test_images/bell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
test/visual_tests/test_images/bg_gradient.jpg
Normal file
BIN
test/visual_tests/test_images/bg_gradient.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 885 KiB |
BIN
test/visual_tests/test_images/settings.png
Normal file
BIN
test/visual_tests/test_images/settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
53
test/visual_tests/test_new_menu_design.py
Normal file
53
test/visual_tests/test_new_menu_design.py
Normal file
@ -0,0 +1,53 @@
|
||||
import customtkinter
|
||||
import tkinter
|
||||
|
||||
# customtkinter.set_appearance_mode("light")
|
||||
|
||||
root_tk = customtkinter.CTk()
|
||||
root_tk.geometry("600x500")
|
||||
|
||||
menu = tkinter.Menu(tearoff=0, bd=0, relief=tkinter.FLAT, activeforeground="red")
|
||||
menu.add_command(label="System")
|
||||
menu.add_command(label="Light")
|
||||
menu.add_command(label="Dark")
|
||||
|
||||
|
||||
class CTkMenu(tkinter.Toplevel):
|
||||
def __init__(self, master, x, y, options):
|
||||
super().__init__(bg="black")
|
||||
super().overrideredirect(True)
|
||||
#self.wm_attributes("-transparentcolor", "black")
|
||||
super().geometry(f"120x{len(options) * (25 + 4) + 4}+{x}+{y}")
|
||||
super().lift()
|
||||
super().transient(master)
|
||||
self.resizable(False, False)
|
||||
super().focus_force()
|
||||
self.focus()
|
||||
|
||||
self.frame = customtkinter.CTkFrame(self, border_width=0, width=120, corner_radius=10, border_color="gray4", fg_color="#333740")
|
||||
self.frame.grid(row=0, column=0, sticky="nsew", rowspan=len(options) + 2, columnspan=1)
|
||||
|
||||
self.frame.grid_rowconfigure(0, minsize=2)
|
||||
self.frame.grid_rowconfigure(len(options) + 1, minsize=2)
|
||||
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.buttons = []
|
||||
for index, option in enumerate(options):
|
||||
button = customtkinter.CTkButton(self.frame, height=25, width=108, fg_color="#333740", text_color="gray74", hover_color="#272A2E", corner_radius=8)
|
||||
button.text_label.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="w")
|
||||
button.grid(row=index + 1, column=0, padx=4, pady=2)
|
||||
self.buttons.append(button)
|
||||
|
||||
# master.bind("<Configure>", self.window_drag())
|
||||
|
||||
|
||||
|
||||
|
||||
def open_menu():
|
||||
menu = CTkMenu(root_tk, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
|
||||
|
||||
button = customtkinter.CTkButton(command=open_menu, height=50)
|
||||
button.pack(pady=20)
|
||||
|
||||
root_tk.mainloop()
|
206
test/visual_tests/test_scaling/complex_example.py
Normal file
206
test/visual_tests/test_scaling/complex_example.py
Normal file
@ -0,0 +1,206 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
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.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed
|
||||
|
||||
# ============ create two frames ============
|
||||
|
||||
# configure grid layout (2x1)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
|
||||
self.frame_left = customtkinter.CTkFrame(master=self,
|
||||
width=180,
|
||||
corner_radius=0)
|
||||
self.frame_left.grid(row=0, column=0, sticky="nswe")
|
||||
|
||||
self.frame_right = customtkinter.CTkFrame(master=self)
|
||||
self.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)
|
||||
|
||||
# ============ frame_left ============
|
||||
|
||||
# configure grid layout (1x11)
|
||||
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",
|
||||
text_font=("Roboto Medium", -16)) # font name and size in px
|
||||
self.label_1.grid(row=1, column=0, pady=10, padx=10)
|
||||
|
||||
self.button_1 = customtkinter.CTkButton(master=self.frame_left,
|
||||
text="CTkButton 1",
|
||||
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",
|
||||
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",
|
||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
||||
command=self.button_event)
|
||||
self.button_3.grid(row=4, column=0, pady=10, padx=20)
|
||||
|
||||
self.switch_1 = customtkinter.CTkSwitch(master=self.frame_left)
|
||||
self.switch_1.grid(row=9, column=0, pady=10, padx=20, sticky="w")
|
||||
|
||||
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")
|
||||
|
||||
# ============ frame_right ============
|
||||
|
||||
# configure grid layout (3x7)
|
||||
self.frame_right.rowconfigure((0, 1, 2, 3), weight=1)
|
||||
self.frame_right.rowconfigure(7, weight=10)
|
||||
self.frame_right.columnconfigure((0, 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=2, rowspan=4, pady=20, padx=20, sticky="nsew")
|
||||
|
||||
# ============ frame_info ============
|
||||
|
||||
# configure grid layout (1x1)
|
||||
self.frame_info.rowconfigure(0, weight=1)
|
||||
self.frame_info.columnconfigure(0, weight=1)
|
||||
|
||||
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" ,
|
||||
height=100,
|
||||
fg_color=("white", "gray38"), # <- custom tuple-color
|
||||
justify=tkinter.LEFT)
|
||||
self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15)
|
||||
|
||||
self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info)
|
||||
self.progressbar.grid(row=1, column=0, sticky="ew", padx=15, pady=15)
|
||||
|
||||
# ============ frame_right ============
|
||||
|
||||
self.radio_var = tkinter.IntVar(value=0)
|
||||
|
||||
self.label_radio_group = customtkinter.CTkLabel(master=self.frame_right,
|
||||
text="CTkRadioButton Group:")
|
||||
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=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=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=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
self.slider_1 = customtkinter.CTkSlider(master=self.frame_right,
|
||||
from_=0,
|
||||
to=1,
|
||||
number_of_steps=3,
|
||||
command=None)
|
||||
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=lambda x: customtkinter.set_user_scaling(x * 2))
|
||||
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=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=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=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=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)
|
||||
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")
|
||||
self.check_box_2.select()
|
||||
|
||||
def button_event(self):
|
||||
print("Button pressed")
|
||||
|
||||
def change_mode(self):
|
||||
if self.switch_2.get() == 1:
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
else:
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
def start(self):
|
||||
self.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.start()
|
76
test/visual_tests/test_scaling/example_background_image.py
Normal file
76
test/visual_tests/test_scaling/example_background_image.py
Normal file
@ -0,0 +1,76 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
from PIL import Image, ImageTk
|
||||
import os
|
||||
|
||||
customtkinter.ScalingTracker.set_window_scaling(1.5)
|
||||
customtkinter.ScalingTracker.set_widget_scaling(1.5)
|
||||
customtkinter.ScalingTracker.set_spacing_scaling(1.5)
|
||||
|
||||
|
||||
customtkinter.set_appearance_mode("Dark") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
APP_NAME = "CustomTkinter background gradient image"
|
||||
WIDTH = 900
|
||||
HEIGHT = 600
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.title(App.APP_NAME)
|
||||
self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
|
||||
self.minsize(App.WIDTH, App.HEIGHT)
|
||||
self.maxsize(App.WIDTH, App.HEIGHT)
|
||||
|
||||
self.protocol("WM_DELETE_WINDOW", self.on_closing)
|
||||
self.bind("<Command-q>", self.on_closing)
|
||||
self.bind("<Command-w>", self.on_closing)
|
||||
self.createcommand('tk::mac::Quit', self.on_closing)
|
||||
|
||||
# load image with PIL and convert to PhotoImage
|
||||
image = Image.open(PATH + "/../test_images/bg_gradient.jpg").resize((self.WIDTH, self.HEIGHT))
|
||||
self.bg_image = ImageTk.PhotoImage(image)
|
||||
|
||||
self.image_label = tkinter.Label(master=self, image=self.bg_image)
|
||||
self.image_label.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||
|
||||
self.frame = customtkinter.CTkFrame(master=self,
|
||||
width=300,
|
||||
height=App.HEIGHT,
|
||||
corner_radius=0)
|
||||
self.frame.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||
|
||||
self.label_1 = customtkinter.CTkLabel(master=self.frame, width=200, height=60,
|
||||
fg_color=("gray70", "gray35"), text="CustomTkinter\ninterface example")
|
||||
self.label_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)
|
||||
|
||||
self.entry_1 = customtkinter.CTkEntry(master=self.frame, corner_radius=20, width=200, placeholder_text="username")
|
||||
self.entry_1.place(relx=0.5, rely=0.52, anchor=tkinter.CENTER)
|
||||
|
||||
self.entry_2 = customtkinter.CTkEntry(master=self.frame, corner_radius=20, width=200, show="*", placeholder_text="password")
|
||||
self.entry_2.place(relx=0.5, rely=0.6, anchor=tkinter.CENTER)
|
||||
|
||||
self.button_2 = customtkinter.CTkButton(master=self.frame, text="Login",
|
||||
corner_radius=6, command=self.button_event, width=200)
|
||||
self.button_2.place(relx=0.5, rely=0.7, anchor=tkinter.CENTER)
|
||||
|
||||
def button_event(self):
|
||||
print("Login pressed - username:", self.entry_1.get(), "password:", self.entry_2.get())
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
def start(self):
|
||||
self.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.start()
|
70
test/visual_tests/test_scaling/simple_example.py
Normal file
70
test/visual_tests/test_scaling/simple_example.py
Normal file
@ -0,0 +1,70 @@
|
||||
import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
|
||||
customtkinter.ScalingTracker.set_window_scaling(1.5)
|
||||
|
||||
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")
|
||||
root_tk.title("CustomTkinter Test")
|
||||
|
||||
root_tk.minsize(480, 480)
|
||||
root_tk.maxsize(520, 520)
|
||||
|
||||
print(customtkinter.ScalingTracker.get_window_scaling(root_tk))
|
||||
|
||||
def button_function():
|
||||
print("Button click", label_1.text_label.cget("text"))
|
||||
|
||||
|
||||
def slider_function(value):
|
||||
customtkinter.set_user_scaling(value * 2)
|
||||
customtkinter.ScalingTracker.set_window_scaling(value * 2)
|
||||
progressbar_1.set(value)
|
||||
|
||||
|
||||
def check_box_function():
|
||||
print("checkbox_1:", checkbox_1.get())
|
||||
|
||||
|
||||
y_padding = 13
|
||||
|
||||
frame_1 = customtkinter.CTkFrame(master=root_tk, corner_radius=15)
|
||||
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
|
||||
|
||||
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
|
||||
label_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
|
||||
progressbar_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=frame_1, corner_radius=8, command=button_function)
|
||||
button_1.pack(pady=y_padding, padx=10)
|
||||
# button_1.configure(state="disabled")
|
||||
|
||||
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_function, from_=0, to=1)
|
||||
slider_1.pack(pady=y_padding, padx=10)
|
||||
slider_1.set(0.5)
|
||||
|
||||
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
|
||||
entry_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1, command=check_box_function)
|
||||
checkbox_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
radiobutton_var = tkinter.IntVar(value=1)
|
||||
|
||||
radiobutton_1 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=1)
|
||||
radiobutton_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
radiobutton_2 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=2)
|
||||
radiobutton_2.pack(pady=y_padding, padx=10)
|
||||
|
||||
s_var = tkinter.StringVar(value="on")
|
||||
|
||||
switch_1 = customtkinter.CTkSwitch(master=frame_1)
|
||||
switch_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
root_tk.mainloop()
|
16
test/visual_tests/test_simple_font_circle.py
Normal file
16
test/visual_tests/test_simple_font_circle.py
Normal file
@ -0,0 +1,16 @@
|
||||
import tkinter
|
||||
|
||||
app = tkinter.Tk()
|
||||
app.geometry("600x500")
|
||||
|
||||
|
||||
canvas = tkinter.Canvas(master=app, highlightthickness=0, bg="gray30")
|
||||
canvas.pack(expand=True, fill="both")
|
||||
|
||||
text_1 = canvas.create_text(100, 100, text="⬤", font=('Helvetica', -4, 'bold'))
|
||||
text_2 = canvas.create_text(100, 200, text="⬤", font=('Helvetica', -8, 'bold'))
|
||||
text_3 = canvas.create_text(100, 300, text="⬤", font=('Helvetica', -12, 'bold'))
|
||||
text_4 = canvas.create_text(100, 400, text="⬤", font=('Helvetica', -20, 'bold'))
|
||||
text_5 = canvas.create_text(400, 400, text="⬤", font=('Helvetica', -100, 'bold'))
|
||||
|
||||
app.mainloop()
|
29
test/visual_tests/test_string_dialog.py
Normal file
29
test/visual_tests/test_string_dialog.py
Normal file
@ -0,0 +1,29 @@
|
||||
import customtkinter
|
||||
import tkinter
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
customtkinter.set_default_color_theme("blue")
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.geometry("400x300")
|
||||
app.title("CTkDialog Test")
|
||||
|
||||
|
||||
def change_mode():
|
||||
if c1.get() == 0:
|
||||
customtkinter.set_appearance_mode("light")
|
||||
else:
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
|
||||
|
||||
def button_click_event():
|
||||
dialog = customtkinter.CTkInputDialog(master=None, text="Type in a number:", title="Test")
|
||||
print("Number:", dialog.get_input())
|
||||
|
||||
|
||||
button = customtkinter.CTkButton(app, text="Open Dialog", command=button_click_event)
|
||||
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||
c1 = customtkinter.CTkCheckBox(app, text="dark mode", command=change_mode)
|
||||
c1.place(relx=0.5, rely=0.8, anchor=tkinter.CENTER)
|
||||
|
||||
app.mainloop()
|
74
test/visual_tests/test_tk_variables.py
Normal file
74
test/visual_tests/test_tk_variables.py
Normal file
@ -0,0 +1,74 @@
|
||||
import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
|
||||
TEST_CONFIGURE = True
|
||||
TEST_REMOVING = False
|
||||
|
||||
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("400x600")
|
||||
root_tk.title("Tkinter Variable Test")
|
||||
|
||||
txt_var = tkinter.StringVar(value="")
|
||||
entry_1 = customtkinter.CTkEntry(root_tk, width=200, textvariable=txt_var)
|
||||
entry_1.pack(pady=15)
|
||||
txt_var.set("new text wjkfjdshkjfb")
|
||||
if TEST_CONFIGURE: entry_1.configure(textvariable=txt_var)
|
||||
if TEST_REMOVING: entry_1.configure(textvariable="")
|
||||
|
||||
label_1 = customtkinter.CTkLabel(root_tk, width=200, textvariable=txt_var)
|
||||
label_1.pack(pady=15)
|
||||
if TEST_CONFIGURE: label_1.configure(textvariable=txt_var)
|
||||
if TEST_REMOVING: label_1.configure(textvariable="")
|
||||
|
||||
button_1 = customtkinter.CTkButton(root_tk, width=200, textvariable=txt_var)
|
||||
button_1.pack(pady=15)
|
||||
int_var = tkinter.IntVar(value=10)
|
||||
if TEST_CONFIGURE: button_1.configure(textvariable=int_var)
|
||||
if TEST_REMOVING: button_1.configure(textvariable="")
|
||||
|
||||
slider_1 = customtkinter.CTkSlider(root_tk, width=200, from_=0, to=3, variable=int_var)
|
||||
slider_1.pack(pady=15)
|
||||
if TEST_CONFIGURE: slider_1.configure(variable=int_var)
|
||||
if TEST_REMOVING: slider_1.configure(variable="")
|
||||
int_var.set(2)
|
||||
|
||||
slider_2 = customtkinter.CTkSlider(root_tk, width=200, from_=0, to=3, variable=int_var)
|
||||
slider_2.pack(pady=15)
|
||||
if TEST_CONFIGURE: slider_2.configure(variable=int_var)
|
||||
if TEST_REMOVING: slider_2.configure(variable="")
|
||||
|
||||
label_2 = customtkinter.CTkLabel(root_tk, width=200, textvariable=int_var)
|
||||
label_2.pack(pady=15)
|
||||
|
||||
progress_1 = customtkinter.CTkProgressBar(root_tk, width=200, variable=int_var)
|
||||
progress_1.pack(pady=15)
|
||||
if TEST_CONFIGURE: progress_1.configure(variable=int_var)
|
||||
if TEST_REMOVING: progress_1.configure(variable="")
|
||||
|
||||
check_var = tkinter.StringVar(value="on")
|
||||
check_1 = customtkinter.CTkCheckBox(root_tk, text="check 1", variable=check_var, onvalue="on", offvalue="off")
|
||||
check_1.pack(pady=15)
|
||||
if TEST_CONFIGURE: check_1.configure(variable=check_var)
|
||||
if TEST_REMOVING: check_1.configure(variable="")
|
||||
print("check_1", check_1.get())
|
||||
|
||||
check_2 = customtkinter.CTkCheckBox(root_tk, text="check 2", variable=check_var, onvalue="on", offvalue="off")
|
||||
check_2.pack(pady=15)
|
||||
if TEST_CONFIGURE: check_2.configure(variable=check_var)
|
||||
if TEST_REMOVING: check_2.configure(variable="")
|
||||
|
||||
label_3 = customtkinter.CTkLabel(root_tk, width=200, textvariable=check_var)
|
||||
label_3.pack(pady=15)
|
||||
label_3.configure(textvariable=check_var)
|
||||
|
||||
def switch_event():
|
||||
print("switch event")
|
||||
|
||||
s_var = tkinter.StringVar(value="on")
|
||||
switch_1 = customtkinter.CTkSwitch(master=root_tk, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off", command=switch_event)
|
||||
switch_1.pack(pady=20, padx=10)
|
||||
switch_1 = customtkinter.CTkSwitch(master=root_tk, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
|
||||
switch_1.pack(pady=20, padx=10)
|
||||
#switch_1.toggle()
|
||||
|
||||
root_tk.mainloop()
|
55
test/visual_tests/test_ttk_frames.py
Normal file
55
test/visual_tests/test_ttk_frames.py
Normal file
@ -0,0 +1,55 @@
|
||||
import tkinter
|
||||
import tkinter.ttk as ttk
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
||||
root_tk = customtkinter.CTk()
|
||||
root_tk.geometry("1400x480")
|
||||
root_tk.title("CustomTkinter TTk Compatibility Test")
|
||||
|
||||
root_tk.grid_rowconfigure(0, weight=1)
|
||||
root_tk.grid_columnconfigure((0, 1, 2, 3, 5, 6), weight=1)
|
||||
|
||||
|
||||
button_0 = customtkinter.CTkButton(root_tk)
|
||||
button_0.grid(padx=20, pady=20, row=0, column=0)
|
||||
|
||||
frame_1 = tkinter.Frame(master=root_tk)
|
||||
frame_1.grid(padx=20, pady=20, row=0, column=1, sticky="nsew")
|
||||
button_1 = customtkinter.CTkButton(frame_1, text="tkinter.Frame")
|
||||
button_1.pack(pady=20, padx=20)
|
||||
|
||||
frame_2 = tkinter.LabelFrame(master=root_tk, text="Tkinter LabelFrame")
|
||||
frame_2.grid(padx=20, pady=20, row=0, column=2, sticky="nsew")
|
||||
button_2 = customtkinter.CTkButton(frame_2, text="tkinter.LabelFrame")
|
||||
button_2.pack(pady=20, padx=20)
|
||||
|
||||
frame_3 = customtkinter.CTkFrame(master=root_tk)
|
||||
frame_3.grid(padx=20, pady=20, row=0, column=3, sticky="nsew")
|
||||
label_3 = customtkinter.CTkLabel(master=frame_3, text="CTkFrame Label", fg_color=("gray95", "gray15"))
|
||||
label_3.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="ew")
|
||||
button_3 = customtkinter.CTkButton(frame_3, text="CTkFrame")
|
||||
button_3.grid(row=1, column=0, padx=20)
|
||||
frame_3.grid_rowconfigure(1, weight=1)
|
||||
frame_3.grid_columnconfigure((0, ), weight=1)
|
||||
|
||||
frame_4 = ttk.Frame(master=root_tk)
|
||||
frame_4.grid(padx=20, pady=20, row=0, column=4, sticky="nsew")
|
||||
button_4 = customtkinter.CTkButton(frame_4, text="ttk.Frame")
|
||||
button_4.pack(pady=20, padx=20)
|
||||
|
||||
frame_5 = ttk.LabelFrame(master=root_tk, text="TTk LabelFrame")
|
||||
frame_5.grid(padx=20, pady=20, row=0, column=5, sticky="nsew")
|
||||
button_5 = customtkinter.CTkButton(frame_5)
|
||||
button_5.pack(pady=20, padx=20)
|
||||
|
||||
frame_6 = ttk.Notebook(master=root_tk)
|
||||
frame_6.grid(padx=20, pady=20, row=0, column=6, sticky="nsew")
|
||||
button_6 = customtkinter.CTkButton(frame_6, text="ttk.Notebook")
|
||||
button_6.pack(pady=20, padx=20)
|
||||
|
||||
ttk_style = ttk.Style()
|
||||
ttk_style.configure(frame_3.winfo_class(), background='red')
|
||||
|
||||
root_tk.mainloop()
|
Reference in New Issue
Block a user