【问题标题】:_tkinter.TclError: couldn't read file "C:\Users\{username}\AppData\Local\Temp\_MEI45522\sv_ttk\sv.tcl": no such file or directory_tkinter.TclError: 无法读取文件 \"C:\\Users\\{username}\\AppData\\Local\\Temp\\_MEI45522\\sv_ttk\\sv.tcl\": 没有这样的文件或目录
【发布时间】:2022-12-21 13:28:57
【问题描述】:

我在我的项目 (.py) 中使用了 Sun Valley Ttk Theme。它在 IDE (Thonny) 上工作,但在我将 .py 文件转换为 .exe 时不起作用。

我收到以下行的错误:sv_ttk.set_theme("light"):

_tkinter.TclError: couldn't read file "C:\Users\{username}\AppData\Local\Temp\_MEI45522\sv_ttk\sv.tcl": no such file or directory.

显然这个目录不存在,但为什么要存在呢?我应该怎么办?

主题文件夹,.py和.exe在同一个目录下。

另外我用过

-add-data 

在转换为 .exe 时将主题文件夹添加为附加文件夹。

【问题讨论】:

  • 你到底把什么传递给了--add-data?
  • @JRiggles Sun-Valley-ttk-theme-main 及其所有子文件夹

标签: python tkinter exe ttk thonny


【解决方案1】:

我和你有同样的问题,这是我的解决方案。我觉得这更像是一个技巧

  1. 找到您在计算机中保存它的 Python 目录

    我的情况:C:UsersPC-NameAppDataLocalProgramsPythonPython310

    1. 转到文件夹tcl -> tk8.6 并将您的自定义 .tcl 文件放在这里(例如:sprites_light.tcl)
    2. 通过pyinstaller Main.exe执行你的程序
    3. 完成后,转到您的程序文件夹。已创建一个新文件夹。 转到dist -> <your-exe-file-name> -> tk 并找到你的 tcl 文件。如果它在那里那么你就成功了
    4. 最后,因为它需要一些*.png文件才能正常运行,所以你也将包含png的文件夹复制到上面的文件夹(在tk文件夹内)

    祝你好运,希望对你有帮助!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2021-06-20
    • 2022-01-08
    • 2014-10-07
    • 1970-01-01
    • 2021-11-24
    相关资源
    最近更新 更多