CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

How do I add an image to a button?

Open Beatriz910 opened this issue 1 year ago • 2 comments

i know ive read the documentation but im a beginner but i tried but it doesnt work

`import customtkinter as ctk from PIL import Image, ImageTk

app = ctk.CTk()

image = Image.open(save.png) photo = ImageTk.PhotoImage(image)

button = ctk.CTkButton(app, image=photo, text="") # Empty text to show only the image button.pack(pady=20, padx=20)

app.mainloop() `

Beatriz910 avatar May 20 '24 15:05 Beatriz910

Make sure the image path is correct.

image_path = './ImageFolder/save.png'
image = Image.open(image_path)

AnonymousVibrate avatar May 21 '24 04:05 AnonymousVibrate

i know ive read the documentation but im a beginner but i tried but it doesnt work

`import customtkinter as ctk from PIL import Image, ImageTk

app = ctk.CTk()

image = Image.open(save.png) photo = ImageTk.PhotoImage(image)

button = ctk.CTkButton(app, image=photo, text="") # Empty text to show only the image button.pack(pady=20, padx=20)

app.mainloop() `

Try it

from PIL import Image

My_image = ctk.CTkImage(light_image=Image.open("image.png"), size=(10, 10))

Button = ctk.CTkButton(app, image=My_image, text="")
Button.pack()

Don't forget the "" in the open() function

you're off to a good start but you forgot the "" here -> image = Image.open(save.png)

Betrayal5414 avatar Jun 06 '24 10:06 Betrayal5414