Tkinter Variable




trace(self, mode, callback)
trace_variable(self, mode, callback)

Define a trace callback for the variable.

MODE is one of "r", "w", "u" for read, write, undefine.
CALLBACK must be a function which is called when
the variable is read, written or undefined.

Return the name of the callback.

为Tkinter Variable定义一个回调函数,用法如下:

>>>import Tkinter
>>> def cc(*pa):
... print 'change'
...
>>> w=Tkinter.Tk()
>>> s=Tkinter.StringVar(w)
>>> s.trace_variable('w',cc)
'19779416cc'
>>> s.set('asfdasdf')
change

第一个参数可以是"r", "w"或"u",分别代表读、写、未定义。第二个参数是一个回调函数。上面的例子是,如果一个窗口变量s被写入,就调用回调函数cc。

没有评论:

发表评论