test_variables.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import tkinter
  2. import customtkinter
  3. TEST_CONFIGURE = True
  4. TEST_REMOVING = False
  5. app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
  6. app.geometry("400x900")
  7. app.title("Tkinter Variable Test")
  8. def checkbox_event():
  9. print("checkbox_event")
  10. txt_var = tkinter.StringVar(value="")
  11. entry_1 = customtkinter.CTkEntry(app, width=200, textvariable=txt_var, placeholder_text="placeholder")
  12. entry_1.pack(pady=15)
  13. txt_var.set("new text test")
  14. if TEST_CONFIGURE: entry_1.configure(textvariable=txt_var)
  15. if TEST_REMOVING: entry_1.configure(textvariable="")
  16. #entry_1.delete(0, "end")
  17. #entry_1.insert(0, "sadsad")
  18. label_1 = customtkinter.CTkLabel(app, width=200, textvariable=txt_var)
  19. label_1.pack(pady=15)
  20. if TEST_CONFIGURE: label_1.configure(textvariable=txt_var)
  21. if TEST_REMOVING: label_1.configure(textvariable="")
  22. button_1 = customtkinter.CTkButton(app, width=200, textvariable=txt_var)
  23. button_1.pack(pady=15)
  24. int_var = tkinter.IntVar(value=10)
  25. if TEST_CONFIGURE: button_1.configure(textvariable=int_var)
  26. if TEST_REMOVING: button_1.configure(textvariable="")
  27. slider_1 = customtkinter.CTkSlider(app, width=200, from_=0, to=3, variable=int_var)
  28. slider_1.pack(pady=15)
  29. if TEST_CONFIGURE: slider_1.configure(variable=int_var)
  30. if TEST_REMOVING: slider_1.configure(variable="")
  31. int_var.set(2)
  32. slider_2 = customtkinter.CTkSlider(app, width=200, from_=0, to=3, variable=int_var)
  33. slider_2.pack(pady=15)
  34. if TEST_CONFIGURE: slider_2.configure(variable=int_var)
  35. if TEST_REMOVING: slider_2.configure(variable="")
  36. label_2 = customtkinter.CTkLabel(app, width=200, textvariable=int_var)
  37. label_2.pack(pady=15)
  38. progress_1 = customtkinter.CTkProgressBar(app, width=200, variable=int_var)
  39. progress_1.pack(pady=15)
  40. if TEST_CONFIGURE: progress_1.configure(variable=int_var)
  41. if TEST_REMOVING: progress_1.configure(variable="")
  42. check_var = tkinter.StringVar(value="on")
  43. check_1 = customtkinter.CTkCheckBox(app, text="check 1", variable=check_var, onvalue="on", offvalue="off", textvariable=txt_var,
  44. command=checkbox_event)
  45. check_1.pack(pady=15)
  46. if TEST_CONFIGURE: check_1.configure(variable=check_var)
  47. if TEST_REMOVING: check_1.configure(variable="")
  48. print("check 1 created")
  49. check_2 = customtkinter.CTkCheckBox(app, text="check 2", variable=check_var, onvalue="on", offvalue="off")
  50. check_2.pack(pady=15)
  51. if TEST_CONFIGURE: check_2.configure(variable=check_var)
  52. if TEST_REMOVING: check_2.configure(variable="")
  53. label_3 = customtkinter.CTkLabel(app, width=200, textvariable=check_var)
  54. label_3.pack(pady=15)
  55. label_3.configure(textvariable=check_var)
  56. def switch_event():
  57. print("switch event")
  58. s_var = tkinter.StringVar(value="on")
  59. switch_1 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off", command=switch_event)
  60. switch_1.pack(pady=20, padx=10)
  61. switch_2 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
  62. switch_2.pack(pady=20, padx=10)
  63. optionmenu_var = tkinter.StringVar(value="test")
  64. optionmenu_1 = customtkinter.CTkOptionMenu(master=app, variable=None, values=["Option 1", "Option 2", "Option 3"])
  65. optionmenu_1.pack(pady=20, padx=10)
  66. optionmenu_1.configure(variable=optionmenu_var)
  67. combobox_1 = customtkinter.CTkComboBox(master=app, values=["Option 1", "Option 2", "Option 3"])
  68. combobox_1.pack(pady=20, padx=10)
  69. combobox_1.configure(variable=optionmenu_var)
  70. radio_1 = customtkinter.CTkRadioButton(app, textvariable=txt_var)
  71. radio_1.pack(pady=20, padx=10)
  72. app.mainloop()