Just installed python 3.13.0 (release) for testing a tkinter app under windows in a venv. Failed to start. After testing I see these results
In the venv
(py313) C:\Users\rptla\tmp\py313>python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> root = tkinter.Tk()
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
root = tkinter.Tk()
File "C:\python313\Lib\tkinter\__init__.py", line 2459, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
C:/python313/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.14/library C:/tcl8.6.14/library
This probably means that Tcl wasn't installed properly.
>>>
in the base Python I get a better outcome
C:\Python313\Lib\tkinter>\python313\python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> root=tkinter.Tk()
>>>
what do I need to do to make tkinter work in the windows venv?
I see the exact same problem in Windows 11. Broken in a venv, works fine outside of a VM. This also means that things like matplotlib donβt work without installing another GUI library. (At least, I assume so. I havenβt installed Qt yet to try it out.)
Additionally, my python 3.13 install is under my user account, not for all users. Just in case someone was wondering, as this is different than the OP.
After doing that the tkinter.Tk() test did not raise an exception and running my app starts OK. However, the app leaves a command window running which itβs not supposed to (the app is declared as a gui_script).
FWIW itβs easier to just set TCL_LIBRARY to point at the tcl\tcl8.6 directory in the installation. Again when I do that Tk() works, but starting my app with say pythonw -mβ¦app leaves a command window lying about.
I am seeing this on Windows 11 too. I installed Python 3.13.0 in the default user profile at %LocalAppData%.
Itβs easy to fix until a new version is released:
Copy the entire tcl8.6 folder from %LocalAppData%\Programs\Python\Python313\tcl
and paste it into %LocalAppData%\Programs\Python\Python313\Lib
Copy the entire tk8.6 folder from %LocalAppData%\Programs\Python\Python313\tcl
and paste it into %LocalAppData%\Programs\Python\Python313\Lib\tcl8.6
i.e. inside the folder you pasted in step 1.
You should end up with a folder structure like this: