diff options
author | Guido van Rossum <guido@python.org> | 1998-01-14 16:44:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-01-14 16:44:34 (GMT) |
commit | e2c6e203c607f2e8791641e937f04a66bbbe8bcb (patch) | |
tree | 9ebf1f4f1a2c81491dfad9ee3ac7a1e1a0db0f5f /Lib | |
parent | f473cb007b774cabcb712e8c4f36fbf2dae1b85d (diff) | |
download | cpython-e2c6e203c607f2e8791641e937f04a66bbbe8bcb.zip cpython-e2c6e203c607f2e8791641e937f04a66bbbe8bcb.tar.gz cpython-e2c6e203c607f2e8791641e937f04a66bbbe8bcb.tar.bz2 |
Add trace methods to class Variable
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/lib-tk/Tkinter.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index fbf90e4..5220c9d 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -63,12 +63,11 @@ _varnum = 0 class Variable: _default = "" def __init__(self, master=None): - global _default_root global _varnum - if master: - self._tk = master.tk - else: - self._tk = _default_root.tk + if not master: + master = _default_root + self._master = master + self._tk = master.tk self._name = 'PY_VAR' + `_varnum` _varnum = _varnum + 1 self.set(self._default) @@ -78,6 +77,17 @@ class Variable: return self._name def set(self, value): return self._tk.globalsetvar(self._name, value) + def trace_variable(self, mode, callback): + cbname = self._master._register(callback) + self._tk.call("trace", "variable", self._name, mode, cbname) + return cbname + trace = trace_variable + def trace_vdelete(self, mode, cbname): + self._tk.call("trace", "vdelete", self._name, mode, cbname) + self._tk.deletecommand(cbname) + def trace_vinfo(self): + return map(self._tk.split, self._tk.splitlist( + self._tk.call("trace", "vinfo", self._name))) class StringVar(Variable): _default = "" |