Skip to content

tkinter.Tk() sometimes fails #126549

Closed as not planned
Closed as not planned

Description

@CharlesKnell

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

Activity

  1. Xiaokang2022 commented on Nov 7, 2024

    @Xiaokang2022
    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.

  2. 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[/+] on Nov 7, 2024
  3. terryjreedy commented on Nov 7, 2024

    @terryjreedy
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions