【发布时间】:2018-11-02 23:04:52
【问题描述】:
我有一长串图片想要加载到Tkinter 画布中。
如果我在 Tkinter 实例上调用 mainloop 之前创建 PIL.PhotoImage 实例,我发现这可行。我将以下内容放入绑定到按键或类似事件的回调函数中:
def onkeypress( event )
canvas.itemconfig( canvas_image, image_content )
image_content = PIL.PhotoImage( file="myfile.jpg" )
mytk.bind( "<Key>", onkeypress )
mytk.mainloop()
...但这要求我在启动主循环之前将整个图像库加载到内存中。如果我尝试仅在需要时创建每个 PIL.PhotoImage:
def onkeypress( event )
image_content = PIL.PhotoImage( file="myfile.jpg" )
canvas.itemconfig( canvas_image, image_content )
mytk.bind( "<Key>", onkeypress )
mytk.mainloop()
然后代码执行没有给我一个错误,但我没有看到画布内容发生变化。
请问我需要做什么才能更改画布内容?
【问题讨论】:
标签: python tkinter python-imaging-library