Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > attaching Tkinter Listbox to python list object

Reply
Thread Tools

attaching Tkinter Listbox to python list object

 
 
Steve Potter
Guest
Posts: n/a
 
      03-13-2007
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....f201ab53cfdbf7
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

 
Reply With Quote
 
 
 
 
James Stroud
Guest
Posts: n/a
 
      03-13-2007
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....f201ab53cfdbf7
> 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
 
Reply With Quote
 
 
 
 
jim-on-linux
Guest
Posts: n/a
 
      03-13-2007
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





 
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
Tkinter Listbox - Different Text colors in one listbox rahulnag22@yahoo.com Python 6 05-31-2007 06:48 AM
attaching mouse events to a flash object Sharkie Javascript 0 12-17-2006 07:20 AM
I set listbox.datasource to fileinfo() object, but no files appear in the listbox. COHENMARVIN ASP .Net 1 10-14-2005 08:19 PM
Attaching an Event Handler(my own Object Method) ?? nukiboy@naver.com Javascript 5 06-06-2005 07:28 PM
Attaching to event in container object Cowboy \(Gregory A. Beamer\) ASP .Net 2 10-28-2003 08:03 PM



Advertisments