mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
78 lines
4.2 KiB
Python
78 lines
4.2 KiB
Python
import PIL.ImageTk
|
|
|
|
import customtkinter
|
|
import tkinter
|
|
from PIL import Image, ImageTk
|
|
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")
|
|
|
|
self.grid_rowconfigure(0, weight=1)
|
|
self.grid_columnconfigure(0, weight=1, minsize=200)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
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")
|
|
|
|
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")
|
|
|
|
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")
|
|
|
|
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")
|
|
|
|
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)
|
|
|
|
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)))
|
|
|
|
def button_function(self):
|
|
print("button pressed")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = App()
|
|
app.mainloop()
|