如何使用 Python 在同一个 TCL shell 上运行命令 [英] How to run commands on same TCL shell using Python

查看:34
本文介绍了如何使用 Python 在同一个 TCL shell 上运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有所有用 TCL 编写的库.我想用 Python 创建一个 GUI,它几乎没有按钮和其他选项.在启动TCL外壳会打开.当我单击按钮时,将在 TCL shell 上执行相应的命令.

I am having all the libraries written in TCL. I want to create a GUI in Python which will have few buttons and other options. In the start TCL shell will open. When I will click the buttons, respective commands will be executed on the TCL shell.

是否可以在不关闭 TCL shell 的情况下在 TCL 的同一个 shell 上触发命令.

Is it possible to fire commands on the same shell of TCL without closing TCL shell.

我搜索了 google 并在 Python 中找到了 Tkniter 模块,但是每次我需要执行命令时它都会打开 TCL shell.

I searched google and find Tkniter module in Python but it will open TCL shell everytime I need to execute command.

推荐答案

你当然可以使用 Tkinter 在同一个 Tcl 解释器中运行一系列命令:

You can certainly use Tkinter to run a series of commands in the same Tcl interpreter:

Python 2.7.9 (default, Feb 28 2016, 05:52:45) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> root = Tkinter.Tk()
>>> root.tk.eval('set msg "hello world"')
'hello world'
>>> root.tk.eval('string length $msg')
'11'
>>> root.tk.eval('foreach x {1 2 4} {puts "$msg $x"}')
hello world 1
hello world 2
hello world 4
''
>>> 

- 这里变量 msg 在一个命令中设置,它的值在以后的命令中使用,如果我们为每个命令创建一个新的解释器,这将不起作用.如果您不想创建 Tk 窗口,只需运行 root.tk.eval('wmwithdraw .') 将其隐藏.

- here the variable msg is set in one command and its value is used in later commands, which would not work if we were creating a new interpreter for each command. If you don't want the Tk window that gets created, just run root.tk.eval('wm withdraw .') to hide it.

如果这不能回答您的问题,您最好解释一下您还需要什么:-)

If this doesn't answer your question you had better explain what else it is that you need :-)

这篇关于如何使用 Python 在同一个 TCL shell 上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆