test_images.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import customtkinter
  2. from PIL import Image, ImageTk
  3. import os
  4. # load images
  5. file_path = os.path.dirname(os.path.realpath(__file__))
  6. image_1 = customtkinter.CTkImage(light_image=Image.open(file_path + "/test_images/add_folder_dark.png"),
  7. dark_image=Image.open(file_path + "/test_images/add_folder_light.png"),
  8. size=(30, 30))
  9. image_1.configure(dark_image=Image.open(file_path + "/test_images/add_folder_light.png"))
  10. image_2 = customtkinter.CTkImage(light_image=Image.open(file_path + "/test_images/bg_gradient.jpg"),
  11. size=(30, 50))
  12. app = customtkinter.CTk()
  13. app.geometry("500x900")
  14. mode_switch = customtkinter.CTkSwitch(app, text="darkmode",
  15. command=lambda: customtkinter.set_appearance_mode("dark" if mode_switch.get() == 1 else "light"))
  16. mode_switch.pack(padx=20, pady=20)
  17. scaling_button = customtkinter.CTkSegmentedButton(app, values=[0.8, 0.9, 1.0, 1.1, 1.2, 1.5, 2.0],
  18. command=lambda v: customtkinter.set_widget_scaling(v))
  19. scaling_button.pack(padx=20, pady=20)
  20. button_1 = customtkinter.CTkButton(app, image=image_1)
  21. button_1.pack(padx=20, pady=20)
  22. button_1 = customtkinter.CTkButton(app, image=image_1, anchor="nw", compound="right", height=50, corner_radius=4)
  23. button_1.pack(padx=20, pady=20)
  24. label_1 = customtkinter.CTkLabel(app, text="", image=image_2, compound="right", fg_color="green", width=0)
  25. label_1.pack(padx=20, pady=20)
  26. label_1.configure(image=image_1)
  27. label_2 = customtkinter.CTkLabel(app, text="text", image=image_2, compound="right", fg_color="red", width=0, corner_radius=10)
  28. label_2.pack(padx=20, pady=20)
  29. label_3 = customtkinter.CTkLabel(app, image=ImageTk.PhotoImage(Image.open(file_path + "/test_images/bg_gradient.jpg").resize((300, 100))),
  30. text="", compound="right", fg_color="green", width=0)
  31. label_3.pack(padx=20, pady=20)
  32. app.mainloop()