Tkinter "scrollregion" verbosity

Greg McFarlane gregm at iname.com
Mon Sep 20 01:00:17 EDT 1999


This is a feature of Tkinter - everything returned by cget (and
configure) is a string.  Consider:

    >>> canvas = Tkinter.Canvas()
    >>> print type(canvas.cget('width'))   # width should be int, right?
    <type 'string'>

Years ago, this annoyed me so much that I rewrote Tkinter to return
the "correct" type for all Tk widget options.  The problem with this
is that Tkinter then needs to contain a mapping from all option names
to return type.  Maintaining this list across versions of Tk (and Blt
and Tix and ...) would become a nightmare, so "always a string" is
probably as good as you'll get :)


On 18 Sep, Randall Hopper wrote:
> Is there a simpler way to get the canvas scroll region than this?
> 
>     GETTING THE CANVAS SCROLL REGION:
> 
>         region = canvas.cget( 'scrollregion' )
>         if not region:
>           raise AttributeError, "No scroll region defined for the canvas"
> 
>         region = map( string.atof, string.split( region ) )
> 
> 
> With Python's normal brevity, it surprised me that this much code was needed.

-- 
Greg McFarlane     INMS Telstra Australia     gregm at iname.com
This e-mail is not GST compliant and not has been checked for bacteria.




More information about the Python-list mailing list