Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > scroll a frame to display several lines of widgets at a time

Reply
Thread Tools

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

 
 
William Gill
Guest
Posts: n/a
 
      09-01-2005
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
 
Reply With Quote
 
 
 
 
Matt Hammond
Guest
Posts: n/a
 
      09-02-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 <>
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.
 
Reply With Quote
 
 
 
 
William Gill
Guest
Posts: n/a
 
      09-02-2005


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 <>
> 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

>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display URL of Frame 2 in Frame 1 nickkaplan@gmail.com Javascript 1 10-16-2007 09:28 AM
RDOC: several related modules in several C files Victor \Zverok\ Shepelev Ruby 3 03-16-2007 04:15 PM
How to display a string in many lines, each lines have a specified length thuyptt@dsp.com.vn C++ 1 12-06-2005 07:26 AM
Asp.Net Calender, how to display 5 lines if there are only 5 lines in one month? Jack ASP .Net 9 10-12-2005 03:44 AM
prevent mouse scroll to scroll in a dropdownlist nicholas ASP .Net 0 12-07-2004 11:26 AM



Advertisments