【发布时间】:2019-09-12 15:45:26
【问题描述】:
我正在尝试从 python 运行 tcl 脚本, tcl 脚本需要命令行参数才能执行,当我从 python 获取 tcl 文件时,它会显示错误提示
tclsh.eval('source "test.tcl"' )
_tkinter.TclError: can't read "::argv": no such variable
我进行了很多搜索,其中大多数询问如何在 tcl 中将参数传递给 python。
python 代码
import tkinter
import sys
tclsh.eval('source "test.tcl"' )
if __name__ == '__main__':
print("hi")
tcl 代码
puts [lindex $::argv 0]
无论如何我可以将 python 参数传递给 tcl 吗?
或
不传递参数并且仍然编译?
因为如果我只编译不带参数的 tcl 脚本,它仍然可以编译
注意:
在 tkinter 文档中它说 tkinter.Tk 是
The Tk class is instantiated without arguments
有没有办法用参数实例化?
索尔:
tclsh.eval('set argv [list]')
tclsh.eval('set argc 0')
我尝试设置一个全局变量,它适用于我在 python 3.6 下
【问题讨论】:
-
检查this question的回答是否有帮助?
-
@Jerry 嗨,我猜不,这个问题是将函数参数传递给 tcl 函数,我正在尝试将参数传递给 tcl 命令行参数...