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

Discussion in 'Python' started by William Gill, Sep 1, 2005.

  1. William Gill

    William Gill Guest

    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
    William Gill, Sep 1, 2005
    #1
    1. Advertising

  2. William Gill

    Matt Hammond Guest

    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.
    Matt Hammond, Sep 2, 2005
    #2
    1. Advertising

  3. William Gill

    William Gill Guest

    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

    >
    >
    >
    >
    William Gill, Sep 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nicholas
    Replies:
    0
    Views:
    440
    nicholas
    Dec 7, 2004
  2. Jack
    Replies:
    9
    Views:
    2,657
  3. Replies:
    1
    Views:
    447
    Jonathan Mcdougall
    Dec 6, 2005
  4. Victor \Zverok\ Shepelev

    RDOC: several related modules in several C files

    Victor \Zverok\ Shepelev, Mar 6, 2007, in forum: Ruby
    Replies:
    3
    Views:
    182
    Max Lapshin
    Mar 16, 2007
  5. Replies:
    1
    Views:
    138
    David Mark
    Oct 16, 2007
Loading...

Share This Page