【问题标题】:Loading images from a directory one at a time in tkinter python在 tkinter python 中一次加载一个目录中的图像
【发布时间】: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


【解决方案1】:

我认为这可能是因为您没有在同一路径中执行代码。尝试在与您的程序相同的路径中像“python3 init.py”一样简单地执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    相关资源
    最近更新 更多