如何找到Tkinter当前使用的Tcl/Tk库的路径? [英] How to find the path of Tcl/Tk library that Tkinter is currently using?
问题描述
TCL_LIBRARY
和 TK_LIBRARY
环境变量可用于绑定 Tkinter 与正确的 Tcl/Tk 安装.
TCL_LIBRARY
and TK_LIBRARY
environment variables can be used to bind Tkinter with proper Tcl/Tk installation.
如何从工作的 Tkinter 实例中获取 Tcl/Tk 的位置?
How to get the location of Tcl/Tk from working Tkinter instance?
(我正在使用 Tkinter 在非虚拟 Python 中运行前端,我需要在虚拟环境中运行 tkinter 子进程.虚拟 Python 找不到 Tcl/Tk.我可以指定 TCL_LIBRARY
和 TK_LIBRARY
手动,但我想要更通用的解决方案并从父进程中提取此信息.)
(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.)
推荐答案
自己找到了解决方案:
import tkinter
root = tkinter.Tk()
print(root.tk.exprstring('$tcl_library'))
print(root.tk.exprstring('$tk_library'))
这篇关于如何找到Tkinter当前使用的Tcl/Tk库的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!