By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

scroll a frame to display several lines of widgets at a time

P: n/a
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
Sep 1 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 <no*****@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.
Sep 2 '05 #2

P: n/a


Matt Hammond wrote:
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.
I need to re-think things a little. I wanted to be able to quickly
scroll through several hundred entries in the db, and check off (yes/no)
which have been reviewed, updated, or whatever.

I will look at having a fixed number of display widgets and scrolling
through the underlying data to determine which records are currently
displayed/editable.

My first pass was db -> display/edit widgets -> db. So I jumped
(incorrectly) to wanting to 'hold' all record in widgets for
editing.There's no reason I can't use:

db -> master list -> slice -> display/edit widgets -> master list -> db.

i.e. a list holding all the data, display/edit slices controlled by a
scrollbar, and storing the final list when done.

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
Probably, not needed now that I have re-thought the situation, but I do
have several occasions where i need to view and select/deselect 50 or 60
options (checkbuttons). So this will make them much more manageable.

Thanks,

Bill

On Thu, 01 Sep 2005 14:33:36 +0100, William Gill <no*****@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


Sep 2 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.