Hem*_*nth 6 python tkinter tcl
是否可以从Python调用具有函数指针(或回调函数)的Tcl过程?我正在使用Tkinter从Python调用Tcl过程.
Python片段:
proc callbackFunc():
print "I am in callbackFunc"
cb = callbackFunc
Tkinter.Tk.call('tclproc::RetrieveInfo', cb)
Run Code Online (Sandbox Code Playgroud)
Tcl片段:
proc tclproc::RetrieveInfo() { callback } {
eval $callback
}
Run Code Online (Sandbox Code Playgroud)
注意我不能将Tcl代码修改为我的应用程序的外部库.
// Hemanth
是的,你的伪代码非常接近.您必须使用Tcl解释器注册您的python代码.这将创建一个调用python代码的tcl命令.然后,只要将此tcl命令传递给需要过程名称的Tcl过程,就可以引用它.它是这样的:
import Tkinter
root=Tkinter.Tk()
# create a python callback function
def callbackFunc():
print "I am in callbackFunc"
# register the callback as a Tcl command. What gets returned
# must be used when calling the function from Tcl
cb = root.register(callbackFunc)
# call a tcl command ('eval', for demonstration purposes)
# that calls our python callback:
root.call('eval',cb)
Run Code Online (Sandbox Code Playgroud)
这里有一些文档:
http://epydoc.sourceforge.net/stdlib/Tkinter.Misc-class.html#register