My goal is to make a graphical interface. I'm looking to use a .PNG file as a button

Viewed 35

I'm a little coding noob, please be forgiving with me. Here's a part of my code. Ah i'm a french speaker so sry :).

Everything is working, but i would like to use my .png file as a button. Is there someone to pull me out of torpor?

Maybe tkInter is not the best choice ... If it is not appropriate or possible, which library can I fall back to?

enter code here: 

# parsonaliser la fenêtre
window.title("Alfred")
window.geometry("400x500")
window.iconbitmap("logoApp.ico")
window.config(background='#1D5ED3')

# création de l'image
width = 337
height = 840
image = PhotoImage(file="JeffreyApp2.1.png").zoom(35).subsample(32)
canvas = Canvas(window, width=width, height=height, bg='#1D5ED3', bd=0, 
highlightthickness=0)
canvas.create_image(width / 2, height / 2, image=image)
canvas.pack(expand=YES)

# Affiche du texte
label_title = Label(frame, text="Alfred, pour vous servir", font=("Helvetica", 20), 
bg='#1D5ED3', fg='white')
label_title.pack()

# ajouter la frame
frame.pack(side=BOTTOM)
# afficher
window.mainloop()
1 Answers
from tkinter import *
from PIL import ImageTk, Image

ws = Tk()
ws.title('PythonGuides')
ws.geometry('300x200')   

dwnd = ImageTk.PhotoImage(Image.open("download.png"))
Button(ws, image=dwnd, command=None).pack(pady=10)

ws.mainloop()

Once I used this code to add an image to my button hope this will help you.

Related