2021-03-08 20:17:36 +03:00
|
|
|
import tkinter
|
|
|
|
import customtkinter # <- import the CustomTkinter module
|
2021-07-13 12:39:52 +03:00
|
|
|
from PIL import Image, ImageTk # <- import PIL for the images
|
2021-08-25 18:02:16 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
PATH = os.path.dirname(os.path.realpath(__file__))
|
2021-03-08 20:17:36 +03:00
|
|
|
|
2021-07-13 12:39:52 +03:00
|
|
|
customtkinter.enable_macos_darkmode()
|
|
|
|
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
|
2021-03-08 20:17:36 +03:00
|
|
|
|
|
|
|
root_tk = tkinter.Tk() # create the Tk window like you normally do
|
2021-11-06 02:35:07 +03:00
|
|
|
root_tk.geometry("400x400")
|
2021-03-08 20:17:36 +03:00
|
|
|
root_tk.title("CustomTkinter Test")
|
|
|
|
|
2021-03-14 17:45:02 +03:00
|
|
|
|
2021-03-08 20:17:36 +03:00
|
|
|
def button_function():
|
|
|
|
print("button pressed")
|
|
|
|
|
2021-03-14 17:45:02 +03:00
|
|
|
|
2021-03-08 20:17:36 +03:00
|
|
|
# load images as PhotoImage
|
2021-08-25 18:02:16 +03:00
|
|
|
settings_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/settings.png").resize((40, 40)))
|
|
|
|
bell_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/bell.png").resize((40, 40)))
|
2021-03-08 20:17:36 +03:00
|
|
|
|
2021-11-06 02:35:07 +03:00
|
|
|
frame_1 = customtkinter.CTkFrame(master=root_tk, width=300, height=350, corner_radius=15)
|
2021-03-08 20:17:36 +03:00
|
|
|
frame_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
|
|
|
|
2021-11-06 02:35:07 +03:00
|
|
|
# button with settings-image and no text
|
2021-11-07 17:12:09 +03:00
|
|
|
button_1 = customtkinter.CTkButton(master=frame_1, image=bell_image, text="", width=60, height=60,
|
2021-03-08 20:17:36 +03:00
|
|
|
corner_radius=10, command=button_function)
|
2021-11-06 02:35:07 +03:00
|
|
|
button_1.place(relx=0.1, rely=0.2, anchor=tkinter.W)
|
2021-03-08 20:17:36 +03:00
|
|
|
|
2021-11-06 02:35:07 +03:00
|
|
|
# button with bell-image and standard compound ("left")
|
2021-03-08 20:17:36 +03:00
|
|
|
button_2 = customtkinter.CTkButton(master=frame_1, image=bell_image, width=60, height=60,
|
|
|
|
corner_radius=10, command=button_function)
|
2021-11-06 02:35:07 +03:00
|
|
|
button_2.place(relx=0.9, rely=0.2, anchor=tkinter.E)
|
|
|
|
|
|
|
|
# button with bell-image and compound="bottom"
|
2021-11-07 17:12:09 +03:00
|
|
|
button_3 = customtkinter.CTkButton(master=frame_1, image=bell_image, text="bell_image", compound="bottom",
|
2021-11-06 02:35:07 +03:00
|
|
|
command=button_function, height=100)
|
2021-11-07 17:12:09 +03:00
|
|
|
button_3.place(relx=0.5, rely=0.55, relwidth=0.5, anchor=tkinter.CENTER)
|
2021-11-06 02:35:07 +03:00
|
|
|
|
|
|
|
# button with settings-image and compound="right"
|
|
|
|
button_4 = customtkinter.CTkButton(master=frame_1, image=settings_image, text="bell_image", compound="right",
|
|
|
|
command=button_function, height=60)
|
|
|
|
button_4.place(relx=0.5, rely=0.85, relwidth=0.5, anchor=tkinter.CENTER)
|
2021-11-07 17:12:09 +03:00
|
|
|
button_4.configure(text=None)
|
|
|
|
|
2021-03-08 20:17:36 +03:00
|
|
|
|
|
|
|
root_tk.mainloop()
|
|
|
|
customtkinter.disable_macos_darkmode()
|