繁体   English   中英

Python TKInter:属性错误:'NoneType'对象没有属性'create_image'

[英]Python TKInter: AttributeError: 'NoneType' object has no attribute 'create_image'

我正在尝试创建Tkinter GUI,并且在尝试将gif图像放在画布上时遇到属性错误。

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)

这是我得到的错误

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

提前致谢。

Tkinter ,方法.pack.grid返回None 他们不返回Widget

解决方法很简单。 将其分为两行:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM