test_segmented_button.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import customtkinter
  2. app = customtkinter.CTk()
  3. app.geometry("600x950")
  4. switch_1 = customtkinter.CTkSwitch(app, text="darkmode", command=lambda: customtkinter.set_appearance_mode("dark" if switch_1.get() == 1 else "light"))
  5. switch_1.pack(padx=20, pady=20)
  6. seg_1 = customtkinter.CTkSegmentedButton(app, values=[])
  7. seg_1.configure(values=["value 1", "Value 2", "Value 42", "Value 123", "longlonglong"])
  8. seg_1.pack(padx=20, pady=20)
  9. frame_1 = customtkinter.CTkFrame(app, height=100)
  10. frame_1.pack(padx=20, pady=20, fill="x")
  11. seg_2_var = customtkinter.StringVar(value="value 1")
  12. seg_2 = customtkinter.CTkSegmentedButton(frame_1, values=["value 1", "Value 2", "Value 42"], variable=seg_2_var)
  13. seg_2.configure(values=[])
  14. seg_2.configure(values=["value 1", "Value 2", "Value 42"])
  15. seg_2.pack(padx=20, pady=10)
  16. seg_2.insert(0, "insert at 0")
  17. seg_2.insert(1, "insert at 1")
  18. label_seg_2 = customtkinter.CTkLabel(frame_1, textvariable=seg_2_var)
  19. label_seg_2.pack(padx=20, pady=10)
  20. frame_1_1 = customtkinter.CTkFrame(frame_1, height=100)
  21. frame_1_1.pack(padx=20, pady=10, fill="x")
  22. switch_2 = customtkinter.CTkSwitch(frame_1_1, text="change fg", command=lambda: frame_1_1.configure(fg_color="red" if switch_2.get() == 1 else "green"))
  23. switch_2.pack(padx=20, pady=20)
  24. seg_3 = customtkinter.CTkSegmentedButton(frame_1_1, values=["value 1", "Value 2", "Value 42"])
  25. seg_3.pack(padx=20, pady=10)
  26. seg_4 = customtkinter.CTkSegmentedButton(app)
  27. seg_4.pack(padx=20, pady=20)
  28. seg_5_var = customtkinter.StringVar(value="kfasjkfdklaj")
  29. seg_5 = customtkinter.CTkSegmentedButton(app, corner_radius=1000, border_width=0, unselected_color="green",
  30. variable=seg_5_var)
  31. seg_5.pack(padx=20, pady=20)
  32. seg_5.configure(values=["1", "2", "3", "4"])
  33. seg_5.insert(0, "insert begin")
  34. seg_5.insert(len(seg_5.cget("values")), "insert 1")
  35. seg_5.insert(len(seg_5.cget("values")), "insert 2")
  36. seg_5.insert(len(seg_5.cget("values")), "insert 3")
  37. seg_5.configure(fg_color="green")
  38. seg_5.set("insert 2")
  39. seg_5.delete("insert 2")
  40. label_seg_5 = customtkinter.CTkLabel(app, textvariable=seg_5_var)
  41. label_seg_5.pack(padx=20, pady=20)
  42. seg_6_var = customtkinter.StringVar(value="kfasjkfdklaj")
  43. seg_6 = customtkinter.CTkSegmentedButton(app, width=300)
  44. seg_6.pack(padx=20, pady=20)
  45. entry_6 = customtkinter.CTkEntry(app)
  46. entry_6.pack(padx=20, pady=(0, 20))
  47. button_6 = customtkinter.CTkButton(app, text="set", command=lambda: seg_6.set(entry_6.get()))
  48. button_6.pack(padx=20, pady=(0, 20))
  49. button_6 = customtkinter.CTkButton(app, text="insert value", command=lambda: seg_6.insert(0, entry_6.get()))
  50. button_6.pack(padx=20, pady=(0, 20))
  51. label_6 = customtkinter.CTkLabel(app, textvariable=seg_6_var)
  52. label_6.pack(padx=20, pady=(0, 20))
  53. seg_6.configure(height=50, variable=seg_6_var)
  54. seg_6.delete("CTkSegmentedButton")
  55. seg_7 = customtkinter.CTkSegmentedButton(app, values=["disabled seg button", "2", "3"])
  56. seg_7.pack(padx=20, pady=20)
  57. seg_7.configure(state="disabled")
  58. seg_7.set("2")
  59. seg_7.configure(height=40, width=400,
  60. dynamic_resizing=False, font=("Times", -20))
  61. app.mainloop()