【发布时间】:2020-07-19 13:40:18
【问题描述】:
只要我将它作为 .py 文件运行,我的程序就可以完美运行,但在转换为 exe 后出现此错误
_tkinter.TclError: couldn't open "C:\Users\MYNAME~1\AppData\Local\Temp\_MEI107362\tkfilebrowser\images\file.png": no such file or directory
为什么要在这里打开那个文件是我的代码
name = askopenfilename( parent=root, initialdir='/', initialfile='tmp', \
filetypes=[("JPG", "*.jpg"), ("MP3", "*.mp3"), ("TXT", "*.txt")])
我使用 pyinstaller 进行转换
【问题讨论】:
-
我不确定该错误是否与您指出的行有关。 file.png 是否可能是您用于 GUI 的图像?
-
不,我没有,我什至没有一个叫做那个的文件,错误中显示的路径不是我机器的真实路径
-
我还有其他三个函数做同样的事情,它们都作为脚本工作,但不在 exe 中
-
_MEI107362 是 pyinstaller bootloader 解压 exe 文件中所有内容的临时文件。您的错误告诉我,可能有一段代码正在尝试使用使用
__file__构建的相对路径来访问 file.png 以确定当前路径。这在 MHO 中没有链接到 askopenfilename。像往常一样,创建一个最小可复制示例会很有帮助。 -
from tkinter import * from tkfilebrowser import askopenfilename root = Tk() def tri(): name = askopenfilename( parent=root, initialdir='\\', initialfile='tmp', \ filetypes= [("JPG", ".jpg"), ("MP3", ".mp3"), ("TXT", "*.txt")]) 按钮(root , text="试试", command = tri).pack() root.geometry("800x800")
标签: python tkinter pyinstaller