Reputation: 1
I'm trying to do a simple Python Canvas. But when I try to do the PhotoImage thing to display it on canvas. it just doesn't show up. There is just a blank 500x500. I don't know if i import something wrong or what. The path file is correct, it just shows a blank canvas.
from tkinter import *
import time
HEIGHT = 500
WIDTH = 500
window = Tk()
canvas = Canvas(window,height=HEIGHT,width=WIDTH)
canvas.update()
photo_Image = PhotoImage(file='C:\\Users\\figue\\OneDrive\\Escritorio\\gatito.png')
my_image = canvas.create_image(0,0,image=photo_Image,anchor=NW)
window.mainloop()
Upvotes: 0
Views: 196
Reputation: 12891
You need to call Tkinter's .pack()
method on your canvas widget. If you do not the widget won't get added to your window thus you won't see anything.
from tkinter import *
import time
HEIGHT = 500
WIDTH = 500
window = Tk()
canvas = Canvas(window,height=HEIGHT,width=WIDTH)
canvas.pack()
photo_Image = PhotoImage(file='C:\\Users\\figue\\OneDrive\\Escritorio\\gatito.png')
my_image = canvas.create_image(0,0,image=photo_Image,anchor=NW)
window.mainloop()
Upvotes: 1