small fixes in CTkToplevel and CTkInputDialog

This commit is contained in:
TomSchimansky
2022-05-22 01:55:58 +02:00
parent 7992f0bdf6
commit fef64638c8
11 changed files with 195 additions and 139 deletions

View File

@ -1,48 +0,0 @@
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

@ -7,12 +7,12 @@ customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark",
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.geometry("400x600")
root_tk.title("CustomTkinter manual scaling test")
#root_tk.minsize(200, 200)
#root_tk.maxsize(520, 520)
root_tk.resizable(True, False)
#root_tk.resizable(True, False)
def button_function():
@ -21,51 +21,36 @@ def button_function():
def slider_function(value):
customtkinter.set_user_scaling(value * 2)
customtkinter.ScalingTracker.set_window_scaling(value * 2)
customtkinter.set_widget_scaling(value * 2)
customtkinter.set_spacing_scaling(value * 2)
customtkinter.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)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
frame_1 = customtkinter.CTkFrame(master=root_tk, height=550, width=300)
frame_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
label_1.pack(pady=y_padding, padx=10)
label_1.place(relx=0.5, y=50, anchor=tkinter.CENTER)
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
progressbar_1.pack(pady=y_padding, padx=10)
progressbar_1.place(relx=0.5, y=100, anchor=tkinter.CENTER)
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")
button_1.place(relx=0.5, y=150, anchor=tkinter.CENTER)
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_function, from_=0, to=1)
slider_1.pack(pady=y_padding, padx=10)
slider_1.place(relx=0.5, y=200, anchor=tkinter.CENTER)
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)
entry_1.place(relx=0.5, y=250, anchor=tkinter.CENTER)
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1)
checkbox_1.place(relx=0.5, y=300, anchor=tkinter.CENTER)
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_1.place(relx=0.5, y=350, anchor=tkinter.CENTER)
radiobutton_2 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=2)
radiobutton_2.pack(pady=y_padding, padx=10)
radiobutton_2.place(relx=0.5, y=400, anchor=tkinter.CENTER)
s_var = tkinter.StringVar(value="on")
switch_1 = customtkinter.CTkSwitch(master=frame_1)
switch_1.pack(pady=y_padding, padx=10)
switch_1.place(relx=0.5, y=450, anchor=tkinter.CENTER)
root_tk.mainloop()

View File

@ -0,0 +1,79 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
customtkinter.ScalingTracker.set_window_scaling(0.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 manual scaling test")
top_tk = customtkinter.CTkToplevel(root_tk)
#root_tk.minsize(200, 200)
#root_tk.maxsize(520, 520)
#root_tk.resizable(True, False)
def button_function():
root_tk.geometry(f"{200}x{200}")
print("Button click", label_1.text_label.cget("text"))
def slider_function(value):
customtkinter.set_widget_scaling(value * 2)
customtkinter.ScalingTracker.set_window_scaling(value * 2)
progressbar_1.set(value)
y_padding = 13
frame_1 = customtkinter.CTkFrame(master=root_tk)
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)
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)
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)
label_1 = customtkinter.CTkLabel(master=top_tk, justify=tkinter.LEFT)
label_1.pack(pady=y_padding, padx=10)
progressbar_1 = customtkinter.CTkProgressBar(master=top_tk)
progressbar_1.pack(pady=y_padding, padx=10)
button_1 = customtkinter.CTkButton(master=top_tk, corner_radius=8, command=button_function)
button_1.pack(pady=y_padding, padx=10)
slider_1 = customtkinter.CTkSlider(master=top_tk, 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=top_tk, placeholder_text="CTkEntry")
entry_1.pack(pady=y_padding, padx=10)
checkbox_1 = customtkinter.CTkCheckBox(master=top_tk)
checkbox_1.pack(pady=y_padding, padx=10)
radiobutton_var = tkinter.IntVar(value=1)
radiobutton_1 = customtkinter.CTkRadioButton(master=top_tk, variable=radiobutton_var, value=1)
radiobutton_1.pack(pady=y_padding, padx=10)
radiobutton_2 = customtkinter.CTkRadioButton(master=top_tk, variable=radiobutton_var, value=2)
radiobutton_2.pack(pady=y_padding, padx=10)
switch_1 = customtkinter.CTkSwitch(master=top_tk)
switch_1.pack(pady=y_padding, padx=10)
root_tk.mainloop()

View File

@ -13,11 +13,12 @@ progressbar_1.grid(row=0, column=0, pady=20, padx=20)
progressbar_2 = customtkinter.CTkProgressBar(root_tk, orient="vertical")
progressbar_2.grid(row=1, column=0, pady=20, padx=20)
slider_1 = customtkinter.CTkSlider(root_tk, orient="horizontal", command=progressbar_1.set)
slider_1 = customtkinter.CTkSlider(root_tk, orient="horizontal", command=progressbar_1.set,
button_corner_radius=3, button_length=20)
slider_1.grid(row=2, column=0, pady=20, padx=20)
slider_2 = customtkinter.CTkSlider(root_tk, orient="vertical", command=progressbar_2.set,
button_corner_radius=2, button_length=20)
button_corner_radius=3, button_length=20)
slider_2.grid(row=3, column=0, pady=20, padx=20)