CustomTkinter/examples/example_button_images.py

78 lines
4.2 KiB
Python
Raw Normal View History

import PIL.ImageTk
import customtkinter
import tkinter
from PIL import Image, ImageTk
2022-01-22 22:28:59 +03:00
import os
PATH = os.path.dirname(os.path.realpath(__file__))
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.geometry("450x260")
self.title("CustomTkinter example_button_images.py")
2022-01-22 22:28:59 +03:00
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1, minsize=200)
2022-01-22 22:28:59 +03:00
self.frame_1 = customtkinter.CTkFrame(master=self, width=250, height=240, corner_radius=15)
self.frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
self.frame_1.grid_columnconfigure(0, weight=1)
self.frame_1.grid_columnconfigure(1, weight=1)
2022-01-22 22:28:59 +03:00
self.settings_image = self.load_image("/test_images/settings.png", 20)
self.bell_image = self.load_image("/test_images/bell.png", 20)
self.add_folder_image = self.load_image("/test_images/add-folder.png", 20)
self.add_list_image = self.load_image("/test_images/add-folder.png", 20)
self.add_user_image = self.load_image("/test_images/add-user.png", 20)
self.chat_image = self.load_image("/test_images/chat.png", 20)
self.home_image = self.load_image("/test_images/home.png", 20)
2022-01-22 22:28:59 +03:00
self.button_1 = customtkinter.CTkButton(master=self.frame_1, image=self.settings_image, text="Add Folder", height=32,
compound="right", command=self.button_function)
self.button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=(20, 10), sticky="ew")
2022-03-13 03:26:18 +03:00
self.button_2 = customtkinter.CTkButton(master=self.frame_1, image=self.add_list_image, text="Add Item", height=32,
compound="right", fg_color="#D35B58", hover_color="#C77C78",
command=self.button_function)
self.button_2.grid(row=2, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
2022-03-13 03:26:18 +03:00
self.button_3 = customtkinter.CTkButton(master=self.frame_1, image=self.chat_image, text="", width=40, height=40,
corner_radius=10, fg_color="gray40", hover_color="gray25",
command=self.button_function)
self.button_3.grid(row=3, column=0, columnspan=1, padx=20, pady=10, sticky="w")
2022-01-22 22:28:59 +03:00
self.button_4 = customtkinter.CTkButton(master=self.frame_1, image=self.home_image, text="", width=40, height=40,
corner_radius=10, fg_color="gray40", hover_color="gray25",
command=self.button_function)
self.button_4.grid(row=3, column=1, columnspan=1, padx=20, pady=10, sticky="e")
2022-03-13 03:26:18 +03:00
self.button_5 = customtkinter.CTkButton(master=self, image=self.add_user_image, text="Add User", width=130, height=60, border_width=2,
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray84", "gray25"),
hover_color="#C77C78", command=self.button_function)
self.button_5.grid(row=0, column=1, padx=20, pady=20)
2022-01-22 22:28:59 +03:00
self.scaling_button = customtkinter.CTkSegmentedButton(self, values=[0.8, 0.9, 1.0, 1.1, 1.2, 1.5],
command=lambda v: customtkinter.set_widget_scaling(v))
self.scaling_button.grid(row=1, column=0, pady=(0, 20))
self.mode_switch = customtkinter.CTkSwitch(self, text="darkmode", onvalue="dark", offvalue="light",
command=lambda: customtkinter.set_appearance_mode(self.mode_switch.get()))
self.mode_switch.grid(row=1, column=1, pady=(0, 20))
def load_image(self, path, image_size):
""" load rectangular image with path relative to PATH """
return ImageTk.PhotoImage(Image.open(PATH + path).resize((image_size, image_size)))
2022-01-22 22:28:59 +03:00
def button_function(self):
print("button pressed")
2022-01-22 22:28:59 +03:00
if __name__ == "__main__":
app = App()
app.mainloop()