From: doughellmann at mindspring.com (Doug Hellmann)
Date: Fri, 09 Apr 1999 07:29:25 -0400
Subject: Q on Tkinter Scrollbar
References: <370CFAC8.32EB0B29@ingr.com>
Message-ID: <370DE495.E98111E3@mindspring.com>
Content-Length: 2155
X-UID: 1592                                                  

Hi, Joseph,

I can't give you any useful tips on the scrollbar, but if I was writing
this I think I would probably subclass the canvas to create a "meter" or
"thermometer" widget to do what you need.  Create a rectangular canvas
(taller than wide), draw the scale (lines and text), then create an
indicator (a triangle?) to point the current value.

In fact, if you're not against using Pmw, there is just such a beast in
the demos or contrib directory.  Now that I think of it, you might find
some useful examples of the scrollbar elsewhere in the Pmw code.  Take a
look http://www.dscpl.com.au/pmw/.

Doug

Joseph Robertson wrote:
> 
> Hi everyone,
> 
> I want to manually control the scrollbar in a tkinter app, i.e. I don't
> want to tie it to another widget as a child.  Below is what I have so
> far.  I can't figure how to make the 'thumb' stay at the returned
> position, or the point where the user drags it.  Right now it always
> pops back to the top.
> 
> I want it to behave like a Scale, but look like a scrollbar.  Think of a
> virtual window on a dataset, where I don't want to load the contents of
> the data set into a listbox (not enough memory).
> 
> Anyone do this before, know of any similar examples, or give me a clue
> where to look next.  I don't want to use extensions or another GUI, it
> needs to be Tkinter.
> 
> Thanks in advance,
> Joe Robertson
> jmrober1 at ingr.com
> 
> >----begin code
> # a manual scrollbar
> #
> # Joe Robertson, jmrober1 at ingr.com
> #
> from Tkinter import *
> 
> class Manual(Frame):
> 
>     def __init__(self, master, **kw):
>         apply(Frame.__init__, (self, master), kw)
>         vscrollbar = Scrollbar(self, orient=VERTICAL)
>         self.canvas = Canvas(self)
>         vscrollbar.config(command=self._vscroll)
>         vscrollbar.pack(fill=Y, side=RIGHT)
>         self.canvas.pack(expand=1, fill=BOTH, side=LEFT)
> 
>     def _vscroll(self, type, *arg):
>         print type
>         if type == 'moveto':
>             for each in arg:
>                 print each
> 
> # doit
> root = Tk()
> f = Manual(root)
> f.pack(expand=1, fill=BOTH)
> root.mainloop()
> 
> >----end code




