test_optionmenu_combobox.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import tkinter
  2. import tkinter.ttk as ttk
  3. import customtkinter
  4. app = customtkinter.CTk()
  5. app.title('Test OptionMenu ComboBox.py')
  6. app.geometry('400x500')
  7. def select_callback(choice):
  8. choice = variable.get()
  9. print("display_selected", choice)
  10. countries = ['Bahamas', 'Canada', 'Cuba', 'United States', "long sdhfhjgdshjafghdgshfhjdsfj"]
  11. variable = tkinter.StringVar()
  12. variable.set("test")
  13. optionmenu_tk = tkinter.OptionMenu(app, variable, *countries, command=select_callback)
  14. optionmenu_tk.pack(pady=10, padx=10)
  15. optionmenu_1 = customtkinter.CTkOptionMenu(app, variable=variable, values=countries, command=select_callback)
  16. optionmenu_1.pack(pady=20, padx=10)
  17. optionmenu_2 = customtkinter.CTkOptionMenu(app, variable=variable, values=countries, command=select_callback,
  18. dynamic_resizing=False)
  19. optionmenu_2.pack(pady=20, padx=10)
  20. combobox_tk = ttk.Combobox(app, values=countries, textvariable=variable)
  21. combobox_tk.pack(pady=10, padx=10)
  22. combobox_1 = customtkinter.CTkComboBox(app, variable=variable, values=countries, command=select_callback, width=300)
  23. combobox_1.pack(pady=20, padx=10)
  24. def set_new_scaling(scaling):
  25. customtkinter.set_window_scaling(scaling)
  26. customtkinter.set_widget_scaling(scaling)
  27. scaling_slider = customtkinter.CTkSlider(app, command=set_new_scaling, from_=0, to=2)
  28. scaling_slider.pack(pady=20, padx=10)
  29. app.mainloop()