2022-01-22 22:28:59 +03:00
|
|
|
import tkinter
|
2022-05-22 21:26:31 +03:00
|
|
|
import customtkinter
|
2022-01-22 22:28:59 +03:00
|
|
|
from PIL import Image, ImageTk # <- import PIL for the images
|
|
|
|
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"
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
|
|
|
app.geometry("450x260")
|
|
|
|
app.title("CustomTkinter example_button_images.py")
|
2022-01-22 22:28:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
def button_function():
|
|
|
|
print("button pressed")
|
|
|
|
|
|
|
|
|
|
|
|
# load images as PhotoImage
|
2022-03-13 03:26:18 +03:00
|
|
|
image_size = 20
|
2022-01-22 22:28:59 +03:00
|
|
|
|
2022-03-13 03:26:18 +03:00
|
|
|
settings_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/settings.png").resize((image_size, image_size)))
|
|
|
|
bell_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/bell.png").resize((image_size, image_size)))
|
|
|
|
|
|
|
|
add_folder_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-folder.png").resize((image_size, image_size), Image.ANTIALIAS))
|
|
|
|
add_list_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-list.png").resize((image_size, image_size), Image.ANTIALIAS))
|
|
|
|
add_user_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-user.png").resize((image_size, image_size), Image.ANTIALIAS))
|
|
|
|
chat_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/chat.png").resize((image_size, image_size), Image.ANTIALIAS))
|
|
|
|
home_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/home.png").resize((image_size, image_size), Image.ANTIALIAS))
|
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
app.grid_rowconfigure(0, weight=1)
|
|
|
|
app.grid_columnconfigure(0, weight=1, minsize=200)
|
2022-01-22 22:28:59 +03:00
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
frame_1 = customtkinter.CTkFrame(master=app, width=250, height=240, corner_radius=15)
|
2022-03-13 03:26:18 +03:00
|
|
|
frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
|
|
|
|
|
|
|
|
frame_1.grid_columnconfigure(0, weight=1)
|
|
|
|
frame_1.grid_columnconfigure(1, weight=1)
|
|
|
|
frame_1.grid_rowconfigure(0, minsize=10) # add empty row for spacing
|
2022-01-22 22:28:59 +03:00
|
|
|
|
2022-03-13 03:26:18 +03:00
|
|
|
button_1 = customtkinter.CTkButton(master=frame_1, image=add_folder_image, text="Add Folder", width=190, height=40,
|
|
|
|
compound="right", command=button_function)
|
|
|
|
button_1.grid(row=1, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
|
2022-01-22 22:28:59 +03:00
|
|
|
|
2022-03-13 03:26:18 +03:00
|
|
|
button_2 = customtkinter.CTkButton(master=frame_1, image=add_list_image, text="Add Item", width=190, height=40,
|
|
|
|
compound="right", fg_color="#D35B58", hover_color="#C77C78",
|
2022-01-22 22:28:59 +03:00
|
|
|
command=button_function)
|
2022-03-13 03:26:18 +03:00
|
|
|
button_2.grid(row=2, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
|
2022-01-22 22:28:59 +03:00
|
|
|
|
|
|
|
button_3 = customtkinter.CTkButton(master=frame_1, image=chat_image, text="", width=50, height=50,
|
2022-03-13 03:26:18 +03:00
|
|
|
corner_radius=10, fg_color="gray40", hover_color="gray25", command=button_function)
|
|
|
|
button_3.grid(row=3, column=0, columnspan=1, padx=20, pady=10, sticky="w")
|
2022-01-22 22:28:59 +03:00
|
|
|
|
|
|
|
button_4 = customtkinter.CTkButton(master=frame_1, image=home_image, text="", width=50, height=50,
|
2022-03-13 03:26:18 +03:00
|
|
|
corner_radius=10, fg_color="gray40", hover_color="gray25", command=button_function)
|
|
|
|
button_4.grid(row=3, column=1, columnspan=1, padx=20, pady=10, sticky="e")
|
2022-01-22 22:28:59 +03:00
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
button_5 = customtkinter.CTkButton(master=app, image=add_user_image, text="Add User", width=130, height=70, border_width=3,
|
2022-03-13 03:26:18 +03:00
|
|
|
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray84", "gray25"), hover_color="#C77C78",
|
2022-01-22 22:28:59 +03:00
|
|
|
command=button_function)
|
2022-03-13 03:26:18 +03:00
|
|
|
button_5.grid(row=0, column=1, padx=20, pady=20)
|
2022-01-22 22:28:59 +03:00
|
|
|
|
2022-05-22 21:26:31 +03:00
|
|
|
app.mainloop()
|