python - 如何在我的 python 项目中本地引用文件?
问题描述
我正在尝试创建一个 exe“游戏”(更多的是概念验证),但是当我这样做时,图像文件不显示。:
parentDirectory = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
photo = tk.PhotoImage(file = os.path.join(parentDirectory, 'okokokokok1.1','imgs', 'spooky.PNG'),width=320,height=240)
老实说,我不明白出了什么问题,请帮助 thx ;3
解决方案
@furas 解决了我的问题,谢谢。他们的评论:
而不是
os.getcwd()
你应该使用os.path.dirname(os.path.abspath(__file__))
,因为getcwd
给了Current Working Directory
这不一定是Directory with Script
推荐阅读
- sql - 使用左连接和分组将 SQL 转换为 LINQ
- swift - 如何仅从全名的姓氏中获取第一个字母?
- r - 使用 R 删除特定变量中不包含 .(dot) 的行
- variables - 从 Octopus 中的租户获取变量
- python - 两个表共有一列
- serialization - 如何在 bincoded 文件中的不同记录之间添加分隔符?
- vba - 将约会转换为电子邮件并发送
- raspbian - 使用 udev 在 Raspbian Stretch lite 上自动挂载 USB 闪存驱动器
- c# - C# 如何将日期 25APR18 转换为 2018-04-26?
- android - React Native Camera 在切换类型时重置缩放