如何在我的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.path.dirname(os.path.abspath(__file__))而不是os.getcwd(),因为getcwd提供的Current Working Directory不必是Directory with Script

最新更新