python - Python IDLE 找不到 .PNG 文件:“没有这样的文件或目录”
问题描述
我遇到了 python idle 找不到我的图像的问题,我将它保存在桌面中为'bg.png'
. python将其显示为未找到问题的错误。
发现的错误是:
Traceback (most recent call last):
File "C:\Users\telta\Desktop\all stuff\stickman game.py", line 233, in
<module>
g=Game()
File "C:\Users\telta\Desktop\all stuff\stickman game.py", line 17, in __init__
self.bg = PhotoImage(file="bg.png")
File "C:\Users\telta\AppData\Local\Programs\Python\Python37- 32\lib\tkinter\__init__.py", line 3545, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\telta\AppData\Local\Programs\Python\Python37- 32\lib\tkinter\__init__.py", line 3501, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "bg.png": no such file or directory
解决方案
改变
self.bg = PhotoImage(file="bg.png")
至
self.bg = PhotoImage(file="C:\complete-path-to-file\bg.png")
将“complete-path-to-file”替换为实际路径!
推荐阅读
- node.js - 如何在 express 应用中管理 Spotify 访问令牌
- python-3.x - 如何根据它在ansible中的寄存器值循环任务
- swift - 在 SwiftUI 的范围错误中找不到“帖子”
- python - 带有可选参数的 Python 函数
- javascript - ReactJs:定义事件处理程序的最佳实践
- maven - LocalRepositoryNotAccessibleException 无法在 /testartifacts/m2repository 创建本地存储库
- azure - 如何在 Azure 服务应用程序上向 docker run 添加其他选项
- python - 已声明但未实例化的类变量
- curl - 如何将缓存添加到 curl/wget?
- java - 相机 X 被另一个 startFocusAndMetering 取消