IntVar - to detect a change in it
Frank Niessink
frankn=news at cs.vu.nl
Mon Aug 2 08:52:40 EDT 1999
Ole-Kristian Villaboe <olevi at my-deja.com> wrote:
> Is there anyway an altering of a variable (Int-, String- or Double-)
> (by the user, via the GUI) could call a function in order to tell the
> environment that it has changed since the initial setting(or a static
> comparison value)
Assuming you're talking about Tkinter here: below's an example of using
trace() to trace a variable:
class VLabel(Label):
"""VLabel class - becomes red when textvariable.valid() returns
false"""
def __init__(self, master, textvariable, **cnf):
apply(Label.__init__, (self, master), cnf)
self.config(textvariable=textvariable)
self.textvariable = textvariable
textvariable.trace('w',self.notify)
def notify(self, *args):
if self.textvariable.valid():
self.config(bg=self.config('bg')[3])
else:
self.config(bg='red')
Everytime the textvariable is changed notify() gets called, which checks
whether the textvariable is valid. If not, the background is colored red,
if it is valid, the background is set to its default color.
HTH, Frank
--
The last ever dolphin message was misinterpreted as a surprisingly
sophisticated attempt to do a double-backwards-somersault through a hoop
whilst whistling the "Star Sprangled Banner", but in fact the message was
this: So long and thanks for all the fish.
-- Douglas Adams, 'The Hitch Hiker's Guide to the Galaxy'
More information about the Python-list
mailing list