[Tkinter-discuss] StringVar() .trace(), .trace_vdelete() use

Bob Greschke bob at passcal.nmt.edu
Thu Mar 7 01:49:49 CET 2013


Hi!

I'm messing with the .trace() function of StringVar()s to, in this case, check to see that the user has not entered more than an allowable number of characters (ckW() below does that).  I'm replacing a monstrous <KeyRelease> .bind method.

I'm using the line below and it seems to work fine, but I'm not sure I understand it.  lambdas really make my head hurt.  Var is a global StringVar() (the line below is in a function of mine that I call to create a Label():Entry() pair of widgets, like "Barcode: ___________").  A form (Toplevel with Entry() fields on it) with an Entry() associated with a StringVar() may be destroyed and brought up multiple times over the course of using the program, so the .trace() may be applied to a given StringVar() multiple times.  Is that a problem?  Do these calls "stack up", or does one identical .trace() cancel the previous one?  In case they do stack up I wanted to do a trace_vdelete() right before this .trace line, but I can't get it right.  Do I need to do it?  If so, how?

    ...
    [Var.trace_vdelete here?]
    Var.trace("w", lambda nm, idx, mode, var = Var: ckW(var, Max))
    ...

Thanks!

Bob



More information about the Tkinter-discuss mailing list