Home > database >  _tkinter.TclError: couldn't read file "C:\Users\{username}\AppData\Local\Temp\_MEI45
_tkinter.TclError: couldn't read file "C:\Users\{username}\AppData\Local\Temp\_MEI45

Time:12-21

I have used Sun Valley Ttk Theme for my project (.py). It works on IDE (Thonny) but doesn't work when I converted the .py file to .exe.

I got this error for the line: 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.

Obviously this directory doesn't exist but why should it? What should I do?

Theme folder, .py and .exe are in the same directory.

Besides I used

-add-data 

to add theme folders as additional while converting to .exe.

CodePudding user response:

You need to include sv_ttk module into the executable by using --collect-data option of PyInstaller:

pyinstaller --onefile --collect-data sv_ttk project.py

Assume project.py is the main python script.

CodePudding user response:

I had the same problem as you and this is my solution. I think it's more like a tricks

  1. Find your Python Directory where you save it in your computer

my case: C:\Users\PC-Name\AppData\Local\Programs\Python\Python310

  1. Go to Folder tcl -> tk8.6 and put your custom .tcl file here (Ex: sprites_light.tcl)
  2. Execute your programs by pyinstaller Main.exe
  3. When Done, Go to your Program Folder. There is a new folder created. Go dist -> <your-exe-file-name> -> tk And find your tcl file . If it's there then you've made it
  4. Finally, because it will need some *.png files to run well, so you will also copy the folder containing the png to the above folder (inside tk folder)

Goodluck, I hope it helpful!!

  • Related