attaching Tkinter Listbox to python list object

Discussion in 'Python' started by Steve Potter, Mar 13, 2007.

  1. Steve  Potter

    Steve Potter Guest

    I am trying to find some method of attaching a Listbox object to a
    list object so as the contents of the list are changed the contents of
    the Listbox will be updated to match. I have found a few references
    to something like this in this old post
    http://groups.google.com/group/comp...read/thread/3a6fe7534c812f55/43f201ab53cfdbf7
    as well as here http://effbot.org/zone/wck-4.htm .

    It just seems that there should be some way of achieving this.

    The only this I can think of is create a subclass of list that deletes
    and then refills the Listbox every time that the list changes, but
    this seems very in efficient.


    Any ideas?

    Steve
     
    Steve Potter, Mar 13, 2007
    #1
    1. Advertising

  2. Steve  Potter

    James Stroud Guest

    Steve Potter wrote:
    > I am trying to find some method of attaching a Listbox object to a
    > list object so as the contents of the list are changed the contents of
    > the Listbox will be updated to match. I have found a few references
    > to something like this in this old post
    > http://groups.google.com/group/comp...read/thread/3a6fe7534c812f55/43f201ab53cfdbf7
    > as well as here http://effbot.org/zone/wck-4.htm .
    >
    > It just seems that there should be some way of achieving this.
    >
    > The only this I can think of is create a subclass of list that deletes
    > and then refills the Listbox every time that the list changes, but
    > this seems very in efficient.
    >
    >
    > Any ideas?
    >
    > Steve
    >


    If you want the listbox to have the interface of a list, you will
    probably not want to do it by inheritance because you are going to have
    to re-write a lot of methods anyway, calling super, etc.

    Probably better is composition in this case, even though inheritance
    feels like the right way if you haven't tried it yet and discovered its
    problems.

    Inherit from object and fill the class with objects designed for the
    job. In fact, make sure you want to abstract your data structure to list
    before you even use that--then create a controller that retrieves
    appropriate info from the data structure (model) and updates the listbox
    (view) accordingly. Use callbacks from the listbox to notify the
    controller if the events in the listbox require modification of the
    list. Have the controller modify the list and then use the modified list
    to update the listbox.

    This is more-or-less MVC. MVC can be as simple as listbox, list, object,
    or more complicated. But you will be happy you began with an MVC design
    at some point in the future. You'll really be happy that you didn't
    inherit from list for this!

    I've looked into the listbox issue and I have found that you will have
    to delete and refill the listbox every time the list is changed. I
    wouldn't worry about speed, though, your computer will keep up with the
    user, no problem. If you look into other GUI frameworks, you'll find
    that they all seem to delete and refill at some level. Its just with
    Tkinter, you have to do this explicitly, which never feels quite right.

    James
     
    James Stroud, Mar 13, 2007
    #2
    1. Advertising

  3. Steve  Potter

    jim-on-linux Guest

    On Monday 12 March 2007 20:34, Steve Potter wrote:
    > I am trying to find some method of attaching a
    > Listbox object to a list object so as the
    > contents of the list are changed the contents
    > of the Listbox will be updated to match. I
    > have found a few references to something like
    > this in this old post
    > http://groups.google.com/group/comp.lang.python
    >/browse_thread/thread/3a6fe7534c812f55/43f201ab5
    >3cfdbf7 as well as here
    > http://effbot.org/zone/wck-4.htm .
    >
    > It just seems that there should be some way of
    > achieving this.
    >
    > The only this I can think of is create a
    > subclass of list that deletes and then refills
    > the Listbox every time that the list changes,
    > but this seems very in efficient.
    >
    >
    > Any ideas?
    >
    > Steve


    Look into the StringVar(),
    class for Tkinter.

    var = stringVar()

    sorry I can't help more, but I think this is what
    you are looking for.

    jim-on-linux

    http:\\www.inqvista.com
     
    jim-on-linux, Mar 13, 2007
    #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. Cowboy \(Gregory A. Beamer\)

    Attaching to event in container object

    Cowboy \(Gregory A. Beamer\), Oct 24, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    374
    Cowboy \(Gregory A. Beamer\)
    Oct 28, 2003
  2. COHENMARVIN
    Replies:
    1
    Views:
    576
    =?Utf-8?B?U3JlZWppdGggUmFtKE1DU0QuTkVUKQ==?=
    Oct 14, 2005
  3. Replies:
    6
    Views:
    611
    Hendrik van Rooyen
    May 31, 2007
  4. Replies:
    5
    Views:
    176
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  5. Sharkie
    Replies:
    0
    Views:
    200
    Sharkie
    Dec 17, 2006
Loading...

Share This Page