Python Tkinter throwing Tcl error

前端 未结 8 1656
孤城傲影
孤城傲影 2021-02-20 13:23

I am learning basic GUI in Python, and I came across a sample example to read file name from file explorer on Stack Overflow.

from Tkinter import Tk
from tkFileD         


        
8条回答
  •  孤城傲影
    2021-02-20 13:55

    If you are hitting this kind of error in a python -m venv NAME kind of virtual environment (and you actually have tcl installed in your system), then you need to export the paths similarly as suggested by Kamil Czerski in a previous post for virtualenv.

    1. To find out what are your TK and TCL paths, run a python script outside of the venv (source):
    import tkinter
    root = tkinter.Tk()   
    print(root.tk.exprstring('$tcl_library'))   
    print(root.tk.exprstring('$tk_library'))
    
    1. Open your venv configuration file bin/activate and find the place where they export PATH and insert after this (insert correct paths from step 1):
    TCL_LIBRARY="/tcl/path/from/step/1"   
    TK_LIBRARY="/tk/path/from/step/1"   
    TKPATH="/tk/path/from/step/1"  
    export TCL_LIBRARY TK_LIBRARY TKPATH
    
    1. Deactivate (if it was activated) and source again your venv:
    deactivate  
    source bin/activate
    

    The "Tcl missing"-error should be gone.

提交回复
热议问题