4

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.

1 Answer 1

6

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()
Sign up to request clarification or add additional context in comments.

1 Comment

thansks, new it would be something simple

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.