【发布时间】:2021-02-27 08:04:56
【问题描述】:
我需要从绑定到按钮“加载下一个图像”的 GUI 中的当前工作目录加载图像。 到目前为止,我只能加载第一个图像文件然后它给了我一个错误。
下面是我的代码:
def NextFile(self):
currentDirectory = os.getcwd()
FileNames = os.listdir(currentDirectory)
images = []
for name in FileNames:
if ".gif" in name:
images.append(name)
self.imageLabel["image"] = self.image = PhotoImage(file = images)
我收到此错误消息:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 4006, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "SmallWaterFall.gif smokey.gif": no such file or directory
【问题讨论】:
-
images是一个列表,所以file = images不正确。
标签: python python-3.x python-2.7 tkinter