您的位置:首页 > 编程语言 > Python开发

Tk 8.5 and Python nf.py 中的应用

2015-07-02 10:52 627 查看
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

#也可以运行成功.......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: