wasm-demo/demo/ermis-f/python_m/cur/0217

46 lines
1.8 KiB
Plaintext

From: fredrik at pythonware.com (Fredrik Lundh)
Date: Sat, 10 Apr 1999 14:00:51 GMT
Subject: Q on Tkinter Scrollbar
References: <370CFAC8.32EB0B29@ingr.com>
Message-ID: <004f01be835a$c0e15240$f29b12c2@pythonware.com>
Content-Length: 1525
X-UID: 217
Joseph Robertson <jmrober1 at ingr.com> wrote:
> 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.
you're halfways there. as you've seen, the callback given to the scrollbar's
"command" option (your _vscroll callback) is called with "moveto" or "scroll"
events, as described on:
http://www.pythonware.com/library/tkinter/introduction/scrollbar.htm
however, the scrollbar target (your dataset) should respond to this by calling
the scrollbar's "set" method with two floating point values (first and last),
which gives the thumb's position as 0.0 (upper/left) and 1.0 (lower/right).
the target should of course also update the scrollbar if the view changes
by any other reason (e.g. if you load a new dataset).
scrollable widgets like Listbox and Text provide "xscrollcommand" and
"yscrollcommand" options for this purpose.
Cheers /F
fredrik at pythonware.com
http://www.pythonware.com