Tkinter Scrollbar get method

Matthew Dixon Cowles matt at mondoinfo.com
Wed Jul 4 13:43:19 EDT 2001


On Wed, 4 Jul 2001 15:10:34 +0000 (UTC), Lee Harr
<missive at frontiernet.net> wrote:

>I am trying to use the Tkinter Scrollbar class.
>The docs say that the get() method returns a
>two element tuple of values between 0.0 and 1.0
>
>What I am getting, though is a 4 element tuple:

>>>> g = sb.get()
>>>> print g
>(0.0, 0.0, 0.0, 0.0)

Lee,
That is odd and I don't know just why that is.

It seems that scrollbars return four items until they've been set
once:

>>> from Tkinter import *
>>> root=Tk()
>>> sb=Scrollbar(root)
>>> sb.pack(side=LEFT,fill=Y)
>>> sb.get()
(0.0, 0.0, 0.0, 0.0)
>>> sb.set(0.0,1.0)
>>> sb.get()
(0.0, 1.0)

The good news is that they work fine in practice. Mostly, you don't
have to use their get() and set() methods directly.  Generally, the
thing you want to scroll has the corresponding xview and yview methods
and it's just a matter of hooking them up. There's a good example of
doing that with a listbox in Fredrik Lundh's excellent An Introduction
to Tkinter at (wrapped for line length):

http://www.pythonware.com/library/tkinter/
  introduction/x7205-patterns.htm

(The whole document is a very valuable resource.) If the standard
Tkinter widgets don't provide the scrollable things you need, Pmw
probably does. Pmw is at:

http://pmw.sourceforge.net/

Among other very convenient widgets, Pmw adds scrolled frames and text
widgets. Still, there are times when it's necessary to do one's own
scrolling and that works fine as long as you do a set() on the
scrollbar before you do a get(). That must be true -- I have an app
that I've been working on for a year in which I need to do my own
scrolling and never ran into the 4-tuple.

Regards,
Matt



More information about the Python-list mailing list