+ 1

How do I add pictures/photos to a tkinter window?

29th Oct 2019, 3:02 PM
Amitoj Singh
Amitoj Singh - avatar
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
29th Oct 2019, 3:58 PM
Preyas
Preyas - avatar
+ 1
And if you wanna work with pictures in python, I advise you installing Pillow library.
29th Oct 2019, 4:26 PM
Théophile
Théophile - avatar
+ 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
29th Oct 2019, 8:39 PM
Sousou
Sousou - avatar