Anu*_*nub 5 python tkinter tcl
使用下面的代码,我可以调用Proc.tcl文件中的所有过程,但我想单独调用诸如sum或sub之类的过程,请让我知道任何其他可能调用它
我的proc文件程序,
puts "hello"
proc sum {a b} {
set c [expr $a + $b]
puts "Addition: $c "
}
proc sub {a b} {
set c [expr $a - $b]
puts "Substraction: $c "
}
Run Code Online (Sandbox Code Playgroud)
我的主文件程序,
import Tkinter
import os
r=Tkinter.Tk()
r.tk.eval('source proc.tcl')
Run Code Online (Sandbox Code Playgroud)
继续你:
>>> import Tkinter
>>> r = Tkinter.Tk()
>>> r.tk.eval('proc sum {a b} {set c [expr {$a + $b}]; puts "Sum $c"; return $c}')
''
>>> r.tk.eval('sum 2 5')
Sum 7
'7'
Run Code Online (Sandbox Code Playgroud)
因此,在您的情况下,您可以使用tcl文件r.tk.eval("sum 5 5")来调用该过程.
注意:始终在tcl中使用expr表达式.如上面的例子.
我不知道tcl,但这看似合乎逻辑:
import tkinter
r=tkinter.Tk()
r.tk.eval('source proc.tcl')
r.tk.eval('sum 1 2')
r.tk.eval('sub 1 2')
>>> hello
>>> Addition: 3
>>> Substraction: -1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12481 次 |
| 最近记录: |