test_ctk.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import time
  2. import customtkinter
  3. class TestCTk():
  4. def __init__(self):
  5. self.root_ctk = customtkinter.CTk()
  6. self.root_ctk.title("TestCTk")
  7. def clean(self):
  8. self.root_ctk.quit()
  9. self.root_ctk.withdraw()
  10. def main(self):
  11. self.execute_tests()
  12. self.root_ctk.mainloop()
  13. def execute_tests(self):
  14. print("\nTestCTk started:")
  15. start_time = 0
  16. self.root_ctk.after(start_time, self.test_geometry)
  17. start_time += 100
  18. self.root_ctk.after(start_time, self.test_scaling)
  19. start_time += 100
  20. self.root_ctk.after(start_time, self.test_configure)
  21. start_time += 100
  22. self.root_ctk.after(start_time, self.test_appearance_mode)
  23. start_time += 100
  24. self.root_ctk.after(start_time, self.test_iconify)
  25. start_time += 1500
  26. self.root_ctk.after(start_time, self.clean)
  27. def test_geometry(self):
  28. print(" -> test_geometry: ", end="")
  29. self.root_ctk.geometry("100x200+200+300")
  30. assert self.root_ctk.current_width == 100 and self.root_ctk.current_height == 200
  31. self.root_ctk.minsize(300, 400)
  32. assert self.root_ctk.current_width == 300 and self.root_ctk.current_height == 400
  33. assert self.root_ctk.min_width == 300 and self.root_ctk.min_height == 400
  34. self.root_ctk.maxsize(400, 500)
  35. self.root_ctk.geometry("600x600")
  36. assert self.root_ctk.current_width == 400 and self.root_ctk.current_height == 500
  37. assert self.root_ctk.max_width == 400 and self.root_ctk.max_height == 500
  38. self.root_ctk.maxsize(1000, 1000)
  39. self.root_ctk.geometry("300x400")
  40. self.root_ctk.resizable(False, False)
  41. self.root_ctk.geometry("500x600")
  42. assert self.root_ctk.current_width == 500 and self.root_ctk.current_height == 600
  43. print("successful")
  44. def test_scaling(self):
  45. print(" -> test_scaling: ", end="")
  46. customtkinter.ScalingTracker.set_window_scaling(1.5)
  47. self.root_ctk.geometry("300x400")
  48. assert self.root_ctk._current_width == 300 and self.root_ctk._current_height == 400
  49. assert self.root_ctk.window_scaling == 1.5 * customtkinter.ScalingTracker.get_window_dpi_scaling(self.root_ctk)
  50. self.root_ctk.maxsize(400, 500)
  51. self.root_ctk.geometry("500x500")
  52. assert self.root_ctk._current_width == 400 and self.root_ctk._current_height == 500
  53. customtkinter.ScalingTracker.set_window_scaling(1)
  54. assert self.root_ctk._current_width == 400 and self.root_ctk._current_height == 500
  55. print("successful")
  56. def test_configure(self):
  57. print(" -> test_configure: ", end="")
  58. self.root_ctk.configure(bg="white")
  59. assert self.root_ctk.cget("fg_color") == "white"
  60. self.root_ctk.configure(background="red")
  61. assert self.root_ctk.cget("fg_color") == "red"
  62. assert self.root_ctk.cget("bg") == "red"
  63. self.root_ctk.config(fg_color=("green", "#FFFFFF"))
  64. assert self.root_ctk.cget("fg_color") == ("green", "#FFFFFF")
  65. print("successful")
  66. def test_appearance_mode(self):
  67. print(" -> test_appearance_mode: ", end="")
  68. customtkinter.set_appearance_mode("light")
  69. self.root_ctk.config(fg_color=("green", "#FFFFFF"))
  70. assert self.root_ctk.cget("bg") == "green"
  71. customtkinter.set_appearance_mode("dark")
  72. assert self.root_ctk.cget("bg") == "#FFFFFF"
  73. print("successful")
  74. def test_iconify(self):
  75. print(" -> test_iconify: ", end="")
  76. self.root_ctk.iconify()
  77. self.root_ctk.after(100, self.root_ctk.deiconify)
  78. print("successful")
  79. if __name__ == "__main__":
  80. TestCTk().main()