test_font.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import customtkinter
  2. app = customtkinter.CTk()
  3. app.geometry("1200x1000")
  4. app.grid_rowconfigure(0, weight=1)
  5. app.grid_columnconfigure((0, 1), weight=1)
  6. frame_1 = customtkinter.CTkFrame(app)
  7. frame_1.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)
  8. frame_2 = customtkinter.CTkFrame(app)
  9. frame_2.grid(row=0, column=1, sticky="nsew", padx=10, pady=10)
  10. def set_scaling(scaling):
  11. customtkinter.set_widget_scaling(scaling)
  12. scaling_button = customtkinter.CTkSegmentedButton(frame_1, values=[0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.5, 2.0], command=set_scaling)
  13. scaling_button.pack(pady=(2, 10))
  14. b = customtkinter.CTkButton(frame_1, text="single name", font=("Times", ))
  15. b.pack(pady=2)
  16. b = customtkinter.CTkButton(frame_1, text="name with size", font=("Times", 18))
  17. b.pack(pady=2)
  18. b = customtkinter.CTkButton(frame_1, text="name with negative size", font=("Times", -18))
  19. b.pack(pady=2)
  20. b = customtkinter.CTkButton(frame_1, text="extra keywords", font=("Times", -18, "bold italic underline overstrike"))
  21. b.pack(pady=2)
  22. b = customtkinter.CTkButton(frame_1, text="object default")
  23. b.pack(pady=(10, 2))
  24. b = customtkinter.CTkButton(frame_1, text="object single name", font=customtkinter.CTkFont("Times"))
  25. b.pack(pady=2)
  26. b = customtkinter.CTkButton(frame_1, text="object with name and size", font=customtkinter.CTkFont("Times", 18))
  27. b.pack(pady=2)
  28. b = customtkinter.CTkButton(frame_1, text="object with name and negative size", font=customtkinter.CTkFont("Times", -18))
  29. b.pack(pady=2)
  30. b = customtkinter.CTkButton(frame_1, text="object with extra keywords",
  31. font=customtkinter.CTkFont("Times", -18, weight="bold", slant="italic", underline=True, overstrike=True))
  32. b.pack(pady=2)
  33. b1 = customtkinter.CTkButton(frame_1, text="object default modified")
  34. b1.pack(pady=(10, 2))
  35. b1.cget("font").configure(size=9)
  36. print("test_font.py:", b1.cget("font").cget("size"), b1.cget("font").cget("family"))
  37. b2 = customtkinter.CTkButton(frame_1, text="object default overridden")
  38. b2.pack(pady=10)
  39. b2.configure(font=customtkinter.CTkFont(family="Times"))
  40. label_font = customtkinter.CTkFont(size=5)
  41. for i in range(30):
  42. l = customtkinter.CTkLabel(frame_2, font=label_font, height=0)
  43. l.grid(row=i, column=0, pady=1)
  44. b = customtkinter.CTkButton(frame_2, font=label_font, height=5)
  45. b.grid(row=i, column=1, pady=1)
  46. c = customtkinter.CTkCheckBox(frame_2, font=label_font)
  47. c.grid(row=i, column=2, pady=1)
  48. c = customtkinter.CTkComboBox(frame_2, font=label_font, dropdown_font=label_font, height=15)
  49. c.grid(row=i, column=3, pady=1)
  50. e = customtkinter.CTkEntry(frame_2, font=label_font, height=15, placeholder_text="testtest")
  51. e.grid(row=i, column=4, pady=1)
  52. o = customtkinter.CTkOptionMenu(frame_2, font=label_font, height=15, width=50)
  53. o.grid(row=i, column=5, pady=1)
  54. r = customtkinter.CTkRadioButton(frame_2, font=label_font, height=15, width=50)
  55. r.grid(row=i, column=6, pady=1)
  56. s = customtkinter.CTkSwitch(frame_2, font=label_font, height=15, width=50)
  57. s.grid(row=i, column=7, pady=1)
  58. frame_2.grid_columnconfigure((0, 1, 2, 3, 4), weight=1)
  59. def change_font():
  60. import time
  61. t1 = time.perf_counter()
  62. label_font.configure(size=10, overstrike=True)
  63. t2 = time.perf_counter()
  64. print("change_font:", (t2-t1)*1000, "ms")
  65. app.after(3000, change_font)
  66. app.after(6000, lambda: label_font.configure(size=8, overstrike=False))
  67. app.mainloop()