【问题标题】:Tkinter or Python does and does not recognize file locationTkinter 或 Python 可以识别和不识别文件位置
【发布时间】:2013-05-16 11:16:13
【问题描述】:

大家好,我遇到了这个错误

Traceback (most recent call last):
  File "C:/Users/Deaven And Teigan/Documents/Python Projects/Tkinter Tut.py", line 16, in <module>
    background_label = Label(image=b'C:\Users\Deaven And Teigan\Documents\Python Projects\Teigan.gif')
  File "C:\Python33\lib\tkinter\__init__.py", line 2596, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Python33\lib\tkinter\__init__.py", line 2075, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "C:\Users\Deaven And Teigan\Documents\Python Projects\Teigan.gif" doesn't exist

问题是属性菜单中的文件位置是

C:\Users\Deaven And Teigan\Documents\Python 项目

文件名是

泰根

文件类型为.gif

虽然 Python 知道它在哪里,但我通过从 IDLE 中的新窗口选择中选择的编辑器内的弹出列表中进行选择来创建该路径。

这不是我唯一一次从弹出菜单中选择一个文件,python 无法识别它。

可能出了什么问题?

【问题讨论】:

  • 所以你是说从其他位置加载文件没有问题?

标签: python file tkinter label gif


【解决方案1】:

仔细查看错误消息。它不是告诉您 file 不存在,而是告诉您具有该名称的 image 不存在。在这种情况下,image 指的是 Tkinter 图像对象。

background_label = Label(image=b'C:\Users\Deaven And Teigan\Documents\Python Projects\Teigan.gif')

image 属性的值不是路径,它应该是 PhotoImageBitmapImage 或兼容的对象。

image = PhotoImage(file='C:\Users\Deaven And Teigan\Documents\Python Projects\Teigan.gif')
background_label = Label(parent, image=photo)
background_label.image = image

background_label.image = image

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2019-06-19
    相关资源
    最近更新 更多