tkinter questions: behavior of StringVar, etc

Eric Brunel eric.brunel at nospam-pragmadev.com
Mon Mar 30 09:37:09 CEST 2009


Alan G Isaac wrote:
[snip]
> PS If you were also offering an answer to the second question,
> I missed it altogether, but although it is perhaps slightly
> less obvious than with a StringVar, I would ask the same
> basic question of an IntVar: why does it not behave more
> like an int?  E.g., why is ``int(IntVar(value=5))`` an
> error, or at least, why is ``str(IntVar(value=5))`` the name
> of the IntVar instead of '5'?

The string representation of Tkinter objects seems to be a design principle in
this module: it'll always evaluate to the representation this object has at
tcl level. Since a XxxVar is represented by an actual variable at tcl level,
its string representation is the name of this variable. I guess it's quite
easier to build the commands that'll be passed to the tcl interpreter this
way: you don't have to check the type of the objects you handle, but pass them
through str and insert the result directly in the command.

HTH
 - Eric -



More information about the Python-list mailing list