add tests

This commit is contained in:
Tom Schimansky 2022-02-21 15:19:04 +01:00
parent 9edb25d6c4
commit 0e845cf281
11 changed files with 436 additions and 2 deletions

View File

@ -1,4 +1,4 @@
__version__ = "2.2"
__version__ = "2.3"
from .customtkinter_button import CTkButton
from .customtkinter_slider import CTkSlider

View File

@ -19,7 +19,7 @@ def read(filename):
setup(name="customtkinter",
version="2.2",
version="2.3",
author="Tom Schimansky",
license="Creative Commons Zero v1.0 Universal",
url="https://github.com/TomSchimansky/CustomTkinter",

52
test/changing_bg.py Normal file
View File

@ -0,0 +1,52 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
#root_tk = tkinter.Tk()
root_tk.geometry("400x300")
root_tk.title("CustomTkinter Test")
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
def rgb2hex(rgb_color: tuple) -> str:
return "#{:02x}{:02x}{:02x}".format(round(rgb_color[0]), round(rgb_color[1]), round(rgb_color[2]))
def slider_function(value):
progressbar_1.set(value)
col_1 = rgb2hex((100, 50, value * 250))
col_2 = rgb2hex((100, value * 250, 100))
root_tk.config(bg=col_1)
#root_tk["background"] = (col_1, col_2)
#frame_1["bg_color"] = col_1
frame_1.configure(fg_color=col_2)
#frame_1.configure(fg_color=bg_col)
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)
label_1 = customtkinter.CTkLabel(master=frame_1)
label_1.place(relx=0.5, rely=0.1, anchor=tkinter.CENTER)
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
progressbar_1.place(relx=0.5, rely=0.25, anchor=tkinter.CENTER)
button_1 = customtkinter.CTkButton(master=frame_1, corner_radius=10)
button_1.place(relx=0.5, rely=0.4, anchor=tkinter.CENTER)
button_1.configure(state="disabled")
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_function, from_=0, to=1, progress_color="gray20")
slider_1.place(relx=0.5, rely=0.55, anchor=tkinter.CENTER)
#slider_1.set(1.5)
entry_1 = customtkinter.CTkEntry(master=frame_1)
entry_1.place(relx=0.5, rely=0.75, anchor=tkinter.CENTER)
checkbox_1 = customtkinter.CTkCheckBox(master=root_tk)
checkbox_1.place(relx=0.5, rely=0.9, anchor=tkinter.CENTER)
#frame_1.config(bg_color="red")
root_tk.mainloop()

180
test/complete_test.py Normal file
View File

@ -0,0 +1,180 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
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, border_color=customtkinter.CTkColorManager.MAIN_HOVER,
)
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()

View 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()

16
test/font_rendering.py Normal file
View 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','2','bold'))
text_2 = canvas.create_text(100, 200, text="", font=('Helvetica','4','bold'))
text_3 = canvas.create_text(100, 300, text="", font=('Helvetica','6','bold'))
text_4 = canvas.create_text(100, 400, text="", font=('Helvetica',8,'bold'))
text_4 = canvas.create_text(400, 400, text="", font=('Helvetica',80,'bold'))
app.mainloop()

48
test/grid_system_test.py Normal file
View 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()

View File

@ -0,0 +1,41 @@
import tkinter
import tkinter.ttk as ttk
app = tkinter.Tk()
app.geometry("400x300")
app.title("Standard Tkinter Test")
def button_function():
print("button pressed")
def slider_function(value):
progressbar_1["value"] = value
y_padding = 6
frame_1 = tkinter.Frame(master=app, width=300, height=260, bg="lightgray")
frame_1.pack(padx=60, pady=20, fill="both", expand=True)
label_1 = tkinter.Label(master=frame_1, text="Label", bg="lightgray")
label_1.pack(pady=y_padding, padx=10)
progressbar_1 = ttk.Progressbar(master=frame_1,style='black.Horizontal.TProgressbar', length=150)
progressbar_1.pack(pady=y_padding, padx=10)
progressbar_1["value"] = 50
button_1 = tkinter.Button(master=frame_1, command=button_function, text="Button", highlightbackground="lightgray")
button_1.pack(pady=y_padding, padx=10)
slider_1 = tkinter.Scale(master=frame_1, command=slider_function, orient="horizontal", bg="lightgray", length=150)
slider_1.pack(pady=y_padding, padx=10)
entry_1 = tkinter.Entry(master=frame_1, highlightbackground="lightgray", width=10)
entry_1.pack(pady=y_padding, padx=10)
checkbox_1 = tkinter.Checkbutton(master=frame_1, bg=frame_1.cget("bg"), text="CheckButton")
checkbox_1.pack(pady=y_padding, padx=10)
app.mainloop()

BIN
test/test_images/bell.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -0,0 +1,64 @@
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)
root_tk.mainloop()