2022-02-21 17:19:04 +03:00
|
|
|
import tkinter
|
2022-05-22 21:26:31 +03:00
|
|
|
import customtkinter
|
2022-02-21 17:19:04 +03:00
|
|
|
|
|
|
|
TEST_CONFIGURE = True
|
|
|
|
TEST_REMOVING = False
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
2022-07-02 01:54:21 +03:00
|
|
|
app.geometry("400x900")
|
2022-05-22 21:26:31 +03:00
|
|
|
app.title("Tkinter Variable Test")
|
2022-02-21 17:19:04 +03:00
|
|
|
|
|
|
|
txt_var = tkinter.StringVar(value="")
|
2022-05-22 21:26:31 +03:00
|
|
|
entry_1 = customtkinter.CTkEntry(app, width=200, textvariable=txt_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
entry_1.pack(pady=15)
|
2022-06-02 01:15:24 +03:00
|
|
|
txt_var.set("new text test")
|
2022-02-21 17:19:04 +03:00
|
|
|
if TEST_CONFIGURE: entry_1.configure(textvariable=txt_var)
|
|
|
|
if TEST_REMOVING: entry_1.configure(textvariable="")
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
label_1 = customtkinter.CTkLabel(app, width=200, textvariable=txt_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
label_1.pack(pady=15)
|
|
|
|
if TEST_CONFIGURE: label_1.configure(textvariable=txt_var)
|
|
|
|
if TEST_REMOVING: label_1.configure(textvariable="")
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
button_1 = customtkinter.CTkButton(app, width=200, textvariable=txt_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
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="")
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
slider_1 = customtkinter.CTkSlider(app, width=200, from_=0, to=3, variable=int_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
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)
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
slider_2 = customtkinter.CTkSlider(app, width=200, from_=0, to=3, variable=int_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
slider_2.pack(pady=15)
|
|
|
|
if TEST_CONFIGURE: slider_2.configure(variable=int_var)
|
|
|
|
if TEST_REMOVING: slider_2.configure(variable="")
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
label_2 = customtkinter.CTkLabel(app, width=200, textvariable=int_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
label_2.pack(pady=15)
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
progress_1 = customtkinter.CTkProgressBar(app, width=200, variable=int_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
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")
|
2022-07-02 01:54:21 +03:00
|
|
|
check_1 = customtkinter.CTkCheckBox(app, text="check 1", variable=check_var, onvalue="on", offvalue="off", textvariable=txt_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
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())
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
check_2 = customtkinter.CTkCheckBox(app, text="check 2", variable=check_var, onvalue="on", offvalue="off")
|
2022-02-21 17:19:04 +03:00
|
|
|
check_2.pack(pady=15)
|
|
|
|
if TEST_CONFIGURE: check_2.configure(variable=check_var)
|
|
|
|
if TEST_REMOVING: check_2.configure(variable="")
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
label_3 = customtkinter.CTkLabel(app, width=200, textvariable=check_var)
|
2022-02-21 17:19:04 +03:00
|
|
|
label_3.pack(pady=15)
|
|
|
|
label_3.configure(textvariable=check_var)
|
|
|
|
|
2022-03-08 17:03:47 +03:00
|
|
|
def switch_event():
|
|
|
|
print("switch event")
|
|
|
|
|
|
|
|
s_var = tkinter.StringVar(value="on")
|
2022-05-22 21:26:31 +03:00
|
|
|
switch_1 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off", command=switch_event)
|
2022-03-08 17:03:47 +03:00
|
|
|
switch_1.pack(pady=20, padx=10)
|
2022-07-02 01:54:21 +03:00
|
|
|
switch_2 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
|
|
|
|
switch_2.pack(pady=20, padx=10)
|
2022-05-27 01:12:37 +03:00
|
|
|
|
|
|
|
optionmenu_var = tkinter.StringVar(value="test")
|
|
|
|
optionmenu_1 = customtkinter.CTkOptionMenu(master=app, variable=optionmenu_var, values=["Option 1", "Option 2", "Option 3"])
|
|
|
|
optionmenu_1.pack(pady=20, padx=10)
|
2022-06-02 00:50:50 +03:00
|
|
|
combobox_1 = customtkinter.CTkComboBox(master=app, values=["Option 1", "Option 2", "Option 3"])
|
|
|
|
combobox_1.pack(pady=20, padx=10)
|
|
|
|
combobox_1.configure(variable=optionmenu_var)
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-07-02 01:54:21 +03:00
|
|
|
radio_1 = customtkinter.CTkRadioButton(app, textvariable=txt_var)
|
|
|
|
radio_1.pack(pady=20, padx=10)
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
app.mainloop()
|