refined example_button_images.py

This commit is contained in:
TomSchimansky 2022-03-13 01:26:18 +01:00
parent 15ecf18449
commit 985771705c
2 changed files with 31 additions and 22 deletions

View File

@ -4,7 +4,7 @@ import customtkinter
import sys
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
customtkinter.set_default_color_theme("dark-blue") # Themes: "blue" (standard), "green", "dark-blue"
class App(customtkinter.CTk):

View File

@ -18,38 +18,47 @@ def button_function():
# load images as PhotoImage
settings_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/settings.png").resize((30, 30)))
bell_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/bell.png").resize((30, 30)))
image_size = 20
add_folder_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-folder.png").resize((30, 30), Image.ANTIALIAS))
add_list_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-list.png").resize((30, 30), Image.ANTIALIAS))
add_user_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-user.png").resize((30, 30), Image.ANTIALIAS))
chat_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/chat.png").resize((30, 30), Image.ANTIALIAS))
home_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/home.png").resize((30, 30), Image.ANTIALIAS))
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))
root_tk.grid_rowconfigure(0, weight=1)
root_tk.grid_columnconfigure(0, weight=1, minsize=200)
frame_1 = customtkinter.CTkFrame(master=root_tk, width=250, height=240, corner_radius=15)
frame_1.pack(padx=20, pady=20, side="left")
frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
button_1 = customtkinter.CTkButton(master=frame_1, image=add_folder_image, text="Add Folder", width=190, height=50,
corner_radius=10, compound="right", command=button_function)
button_1.place(relx=0.5, rely=0.2, anchor=tkinter.CENTER)
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
button_2 = customtkinter.CTkButton(master=frame_1, image=add_list_image, text="Add Item", width=190, height=50,
corner_radius=10, compound="right", fg_color="#D35B58", hover_color="#C77C78",
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")
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",
command=button_function)
button_2.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
button_2.grid(row=2, column=0, columnspan=2, padx=20, pady=10, sticky="ew")
button_3 = customtkinter.CTkButton(master=frame_1, image=chat_image, text="", width=50, height=50,
corner_radius=10, fg_color="gray40", hover_color="gray35", command=button_function)
button_3.place(relx=0.35, rely=0.8, anchor=tkinter.CENTER)
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")
button_4 = customtkinter.CTkButton(master=frame_1, image=home_image, text="", width=50, height=50,
corner_radius=10, fg_color="gray40", hover_color="gray35", command=button_function)
button_4.place(relx=0.65, rely=0.8, anchor=tkinter.CENTER)
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")
button_5 = customtkinter.CTkButton(master=root_tk, image=add_user_image, text="Add User", width=130, height=90, border_width=4,
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray80", "gray25"), hover_color="#C77C78",
button_5 = customtkinter.CTkButton(master=root_tk, image=add_user_image, text="Add User", width=130, height=70, border_width=3,
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray84", "gray25"), hover_color="#C77C78",
command=button_function)
button_5.pack(padx=20, pady=20, side="right")
button_5.grid(row=0, column=1, padx=20, pady=20)
root_tk.mainloop()