gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:31:21 34 4
gpt4 key购买 nike

我正在尝试创建 Tkinter GUI,但在尝试将 gif 图像放在 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)

这是我得到的错误
  canvas_1.create_image(0, 0, image = gif, anchor = NW)
AttributeError: 'NoneType' object has no attribute 'create_image'

提前致谢。

最佳答案

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

修复很简单。将其拆分为 2 行:

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

关于Python TKInter : AttributeError: 'NoneType' object has no attribute 'create_image' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14879205/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com