scroll a frame to display several lines of widgets at a time
Matt Hammond
matt.hammond at rd.bbc.co.uk
Fri Sep 2 07:02:31 EDT 2005
I don't quite understand (if I'm interpreting you correctly) why you want
separate widgets, all displayed at once, for several hundred records -
surely better to just reuse the one set of widgets and have the scrollbar
or back-forward buttons change which record is being displayed in the
widgets.
If you're after replacing widgets, then you need to destroy them first.
Use the self.destroy method and unset/change any variables referencing the
widget so it get a chance to be garbage collected.
However, if you want a scrollable view onto a larger area, what you need
to do is use a Canvas, with a window shape on it. You then put a frame
into that window.
canvas = Tkinter.Canvas( <parent> )
canvas.grid( ... )
winID = self.canvas.create_window(0,0, anchor=Tkinter.NW)
Then later you can add a frame to that window on the canvas:
canvas.itemconfigure( winID, window = <my frame> )
canvas['scrollregion'] = canvas.bbox('all')
Make sure you've created the frame and perhaps called update_idletasks()
to give it a chance to size itself before shoving it onto the canvas.
And of course, the scrollbar!
yscroll = Tkinter.Scrollbar( <parent>, orient=Tkinter.VERTICAL)
yscroll.grid( ... )
yscroll['command'] = canvas.yview
canvas['yscrollcommand'] = yscroll.set
On Thu, 01 Sep 2005 14:33:36 +0100, William Gill <noreply at gcgroup.net>
wrote:
> I need to display a couple of labels and a checkbox from each entry in
> my database. Simple enough, but there are several hundred records, and
> I only want to display 5 or 10 at a time. Can this be accomplished by
> putting everything in a Frame(), using width, height, grid_propagate(0)
> , and a scrollbar? or do I have to grid 5 rows at a time? If the
> latter, can I just grid over the previous 5 or do they have to be
> explicitly removed first.
>
> Thanks.
>
> Bill
--
| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
More information about the Python-list
mailing list