TCL_LIBRARY
and TK_LIBRARY
environment variables can be used to bind Tkinter with proper Tcl/Tk installation.
How to get the location of Tcl/Tk from working Tkinter instance?
(I'm running a frontend in non-virtual Python with working Tkinter and I need to run a tkinter subprocess in a virtual environment. Virtual Python doesn't find Tcl/Tk. I can specify TCL_LIBRARY
and TK_LIBRARY
manually, but I'd like to have more general solution and extract this information from the parent process.)
Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is properly installed on your system, and also showing what version of Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to that version.
In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk(). It helps to display the root window and manages all the other components of the tkinter application. We can initialize the tkinter instance by assigning the variable to it.
As Tcl is a string-interpreted language where everything is a string, evaluating Tcl calls within Python is effectively the same as evaluating a string object containing Tcl code using the interpreter's eval() function.
The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)
Found the solution myself:
import tkinter
root = tkinter.Tk()
print(root.tk.exprstring('$tcl_library'))
print(root.tk.exprstring('$tk_library'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With