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

python, tkinter

Solution

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()

Problem

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.

Original source