import Tkinterroot = Tkinter.Tk()
print Tkinter.TkVersion
def test():
return (1, 2, 3)
root.tk.createcommand("test", test)
x = root.tk.call("test")
print x, type(x)
#python 和 tk 的交互
root.tk.createcommand("test", test): tk.createcommand 把python test 函数注册为tk命令test,
#在python 中执行tk 命令
x = root.tk.call("test")
#nf.py 中的makecommad1
def makecommand1(master, name, func, subst=None, needcleanup=0):
f = Tkinter.CallWrapper(func, subst, master).__call__
master.tk.createcommand(name, f)
return name
#将 func ,subst,master 包装在一起
f=Tkinter.CallWrapper(func, subst, master).__call__
#再将 python 中的f 函数注册tk 的name 命令
master.tk.createcommand(name, f)
#当然这段代码可以不使用包装函数
def makecommand1(master, name, func, subst=None, needcleanup=0):
master.tk.createcommand(name, func)
return name
#也可以运行成功.......