user1816467
user1816467

Reputation:

Python TKInter: AttributeError: 'NoneType' object has no attribute 'create_image'

I'm trying to create a Tkinter GUI and I get an attribute error when trying to put a gif image on the canvas.

canvas_1 = Canvas(width = 800, height = 450, bg = "blue").pack()
gif = PhotoImage(file = "C:\\Users\\Luke\\Desktop\\fb.gif")
canvas_1.create_image(0, 0, image = gif, anchor = NW)

This is the error I'm getting

  canvas_1.create_image(0, 0, image = gif, anchor = NW)
AttributeError: 'NoneType' object has no attribute 'create_image'

Thanks in advance.

Upvotes: 4

Views: 7008

Answers (1)

mgilson
mgilson

Reputation: 309929

In Tkinter, the methods .pack and .grid return None. They don't return the Widget.

The fix is simple. Split it into 2 lines:

canvas_1 = Canvas(width = 800, height = 450, bg = "blue")
canvas_1.pack()

Upvotes: 6

Related Questions