Q on Tkinter Scrollbar

Joseph Robertson jmrober1 at ingr.com
Fri Apr 9 10:47:19 EDT 1999


No thats a scale.

Picture a scrollable canvas spreadsheet table of 58 cols and 90,000+ rows.
Now picture tkinter trying to create that grid, if it doesn't bomb from the
strain it would still take it literally hours to create it.  But since you
can't 'see' anything outside the scrollwindow of at most 60 rows, why try to
create it?  A thermometer or scale looks out of place.  A scrollbar is
expected.  Now let the vertical scrollbar track the 'dataset' and simply show
the 60 rows that the scrollbar points to.  I've done all this in VB, using
Python-Com as the underlying dataset.  Now I am trying to ditch the vb gui
(and its horrible overhead).

Thanks,
Joe Robertson
jmrober1 at ingr.com


Doug Hellmann wrote:

> 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







More information about the Python-list mailing list