我试图在我的python应用程序中使用Canvas在tkinter中插入一个图像。代码相同:
class Welcomepage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
canvas = tk.Canvas(self, width = 1000, height = 1000, bg = 'blue')
canvas.pack(expand = tk.YES, fill = tk.BOTH)
image = tk.PhotoImage(file="ice_mix.gif")
canvas.create_image(480, 258, image = image, anchor = tk.NW)
图像正在从源代码读取,但仍没有显示在框架中。我是新的图形用户界面编程有人请帮助我。在
此代码成功地工作(从USB摄像头获取OpenCV图像并将其放在Tkinter画布中):
这里可能存在的问题是,Python正在对图像进行垃圾收集,因此没有显示出来——这正是@nae的评论所暗示的。将其附加到
self
引用将阻止其被垃圾回收。在上的Tkinter Bookeffbot.org网站解释如下:
相关问题 更多 >
编程相关推荐