Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tkinter.Tk() sometimes fails #126549

Closed
CharlesKnell opened this issue Nov 7, 2024 · 2 comments
Closed

tkinter.Tk() sometimes fails #126549

CharlesKnell opened this issue Nov 7, 2024 · 2 comments
Labels
OS-windows topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@CharlesKnell
Copy link

CharlesKnell commented Nov 7, 2024

Bug report

Bug description:

import PySimpleGUI

or

import FreeSimpleGUI

results in the following Traceback (for import PySimpleGUI):

Traceback (most recent call last):
  File "c:\Users\charl\PYTHON\stackoverflow_questions_2\test_PySimpleGUI_re_tkinter.py", line 4, in <module>
    import PySimpleGUI
  File "C:\Users\charl\PYTHON\stackoverflow_questions_2\.venv313\Lib\site-packages\PySimpleGUI\__init__.py", line 1, in <module>
    from .PySimpleGUI import *
  File "C:\Users\charl\PYTHON\stackoverflow_questions_2\.venv313\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 108, in <module>
    tclversion_detailed = tkinter.Tcl().eval('info patchlevel')
                          ~~~~~~~~~~~^^
  File "C:\Users\charl\AppData\Local\Programs\Python\Python313\Lib\tkinter\__init__.py", line 2572, in Tcl
    return Tk(screenName, baseName, className, useTk)
  File "C:\Users\charl\AppData\Local\Programs\Python\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:/Users/charl/AppData/Local/Programs/Python/Python313/lib/tcl8.6 C:/Users/charl/PYTHON/stackoverflow_questions_2/.venv313/lib/tcl8.6 C:/Users/charl/PYTHON/stackoverflow_questions_2/lib/tcl8.6 C:/Users/charl/PYTHON/stackoverflow_questions_2/.venv313/library C:/Users/charl/PYTHON/stackoverflow_questions_2/library C:/Users/charl/PYTHON/stackoverflow_questions_2/tcl8.6.14/library C:/Users/charl/PYTHON/tcl8.6.14/library



This probably means that Tcl wasn't installed properly.

This does not occur using python 3.12.7

It can be worked around using the following code:

import os
os.environ['TCL_LIBRARY'] = r'C:\Users\charl\AppData\Local\Programs\Python\Python313\tcl\tcl8.6'
os.environ['TK_LIBRARY'] =  r'C:\Users\charl\AppData\Local\Programs\Python\Python313\tcl\tk8.6'

CPython versions tested on:

3.13

Operating systems tested on:

Windows

@CharlesKnell CharlesKnell added the type-bug An unexpected behavior, bug, or error label Nov 7, 2024
@Xiaokang2022
Copy link
Contributor

I'm having a similar issue, only in Python 3.13.0 (Windows). But it doesn't seem like this problem will come up every time, it's weird.

At first, I thought it was something wrong with my environment, but now it seems that I'm not the only one who has encountered it. By the way, I ran into this issue when I was using pytest to test code related to tkinter.

@terryjreedy terryjreedy changed the title When importing PySimpleGUI or FreeSimpleGUI, python ends with "_tkinter.TclError: Can't find a usable init.tcl in the following directories:" tkinter.Tk() sometimes fails Nov 7, 2024
@terryjreedy
Copy link
Member

Closing as a duplicate of #118973 (tkinter fails in installed free-threading build) or, more likely here, #125235 (tkinter fails in venv). Fix for latter in 3.13.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants