+ 1
How do I add pictures/photos to a tkinter window?
3 Respuestas
+ 1
root = tkinter.Tk()
root.geometry("1200x600")
C = Canvas()
filename = PhotoImage(file = "assets/gradient.png")
background_label = Label(root, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()
if you give root.geometry as 1200x600px
the background image also should be in 1200x600px
+ 1
And if you wanna work with pictures in python, I advise you installing Pillow library.
+ 1
https://code.sololearn.com/WoW55z01Qmqg/?ref=app
from tkinter import *
root=Tk()
filename = PhotoImage(file = "sunshine.gif")
canvas=Canvas(root, bg="blue", height=250, width=300)
image = canvas.create_image(50, 50, anchor=NE, image=filename)
canvas.pack()
root.mainloop()
#Not sure, but I think It works