使用TkCon作为REPL类型的Tcl控制台应用程序

时间:2015-01-18 08:21:42

标签: tcl tk

有没有办法让我的简单tcl控制台(REPL类型)应用程序如下所示:

puts "Enter your name"
set name [gets stdin]
puts "You entered: $name --- Enter another name"
set name2 [gets stdin]
puts "You entered: $name2"

可以使用tkcon,实际上我不想在Windows中使用cmd。

我使用tkcon尝试下面的代码:

package require tkcon 
tkcon show

puts "Enter your name"
set name [gets stdin]
puts "You entered: $name ---  Enter another name"
set name2 [gets stdin]
puts "You entered: $name2"

有效。但在执行我的tcl脚本后,它进入交互模式。它应该像一个普通的控制台应用程序。并且它不应该显示" wize-win-3.2%2"提示。

1 个答案:

答案 0 :(得分:2)

您可以做的最简单的事情是在脚本的末尾放置一个明确的exit,可能会有某种延迟。您需要在事件循环中执行延迟,这意味着将exit置于回调中。

after 5000 exit
vwait for-termination;    # Arbitrary variable name ;-)

但是,如果您真的需要首先使用GUI,那么制作简单的Tk应用程序并不是特别困难。