[英]Python - tkinter 'AttributeError: 'NoneType' object has no attribute 'xview''
[英]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.