_tkinter。Tcl错误:找不到包通信



在尝试使用comm包时遇到此问题:

>>> interp = tkinter.Tcl()
>>> interp.eval('package require comm')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_tkinter.TclError: can't find package comm

我在windows 10 上使用python 3.6.8

如果您知道安装comm程序包的目录(包含pkgIndex.tcl的目录或直属父目录(,则在尝试package require程序包之前,应确保该目录位于Tcl的auto_path上。你需要做的功能是:

def add_library_directory(tcl_context, directory_name):
tcl_context.eval("lappend auto_path {}".format(
# This does the trick to make the string substitution fully safe
tkinter._stringify(directory_name)))
interp = tkinter.Tcl()
# Up to you to actually find the location...
add_library_directory(interp, "/path/to/dir")
interp.eval('package require comm')

有关tkinter._stringify的详细信息,尽管它非常有用,但文档量很大,请参阅另一个堆栈溢出问题:

  • 将Python变量传递到`Tkinter.Tcl((.eval((`

解决方案摘要如@Donal所解释https://stackoverflow.com/a/64884895/14656464然后可能是下一个解决方案:Python Tkinter通过将包含comms库的Tcl-lib的脱机版本指向Python环境所期望的位置来抛出Tcl错误。

最新更新