test_states.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import tkinter
  2. import customtkinter
  3. app = customtkinter.CTk()
  4. app.geometry("400x900")
  5. app.title("CustomTkinter Test")
  6. def change_state(widget):
  7. if widget.cget("state") == tkinter.NORMAL:
  8. widget.configure(state=tkinter.DISABLED)
  9. elif widget.cget("state") == tkinter.DISABLED:
  10. widget.configure(state=tkinter.NORMAL)
  11. def widget_click():
  12. print("widget clicked")
  13. button_1 = customtkinter.CTkButton(master=app, text="button_1", command=widget_click)
  14. button_1.pack(padx=20, pady=(20, 10))
  15. button_2 = customtkinter.CTkButton(master=app, text="Disable/Enable button_1", command=lambda: change_state(button_1))
  16. button_2.pack(padx=20, pady=(10, 20))
  17. switch_1 = customtkinter.CTkSwitch(master=app, text="switch_1", command=widget_click)
  18. switch_1.pack(padx=20, pady=(20, 10))
  19. button_2 = customtkinter.CTkButton(master=app, text="Disable/Enable switch_1", command=lambda: change_state(switch_1))
  20. button_2.pack(padx=20, pady=(10, 20))
  21. entry_1 = customtkinter.CTkEntry(master=app, placeholder_text="entry_1")
  22. entry_1.pack(padx=20, pady=(20, 10))
  23. button_3 = customtkinter.CTkButton(master=app, text="Disable/Enable entry_1", command=lambda: change_state(entry_1))
  24. button_3.pack(padx=20, pady=(10, 20))
  25. checkbox_1 = customtkinter.CTkCheckBox(master=app, text="checkbox_1")
  26. checkbox_1.pack(padx=20, pady=(20, 10))
  27. button_4 = customtkinter.CTkButton(master=app, text="Disable/Enable checkbox_1", command=lambda: change_state(checkbox_1))
  28. button_4.pack(padx=20, pady=(10, 20))
  29. radiobutton_1 = customtkinter.CTkRadioButton(master=app, text="radiobutton_1")
  30. radiobutton_1.pack(padx=20, pady=(20, 10))
  31. button_5 = customtkinter.CTkButton(master=app, text="Disable/Enable radiobutton_1", command=lambda: change_state(radiobutton_1))
  32. button_5.pack(padx=20, pady=(10, 20))
  33. optionmenu_1 = customtkinter.CTkOptionMenu(app, values=["test 1", "test 2"])
  34. optionmenu_1.pack(pady=10, padx=10)
  35. button_6 = customtkinter.CTkButton(master=app, text="Disable/Enable optionmenu_1", command=lambda: change_state(optionmenu_1))
  36. button_6.pack(padx=20, pady=(10, 20))
  37. combobox_1 = customtkinter.CTkComboBox(app, values=["test 1", "test 2"])
  38. combobox_1.pack(pady=10, padx=10)
  39. button_7 = customtkinter.CTkButton(master=app, text="Disable/Enable combobox_1", command=lambda: change_state(combobox_1))
  40. button_7.pack(padx=20, pady=(10, 20))
  41. slider_1 = customtkinter.CTkSlider(app)
  42. slider_1.pack(pady=10, padx=10)
  43. button_8 = customtkinter.CTkButton(master=app, text="Disable/Enable slider_1", command=lambda: change_state(slider_1))
  44. button_8.pack(padx=20, pady=(10, 20))
  45. app.mainloop()