473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

attaching Tkinter Listbox to python list object

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

Mar 13 '07 #1
2 2073
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
Mar 13 '07 #2
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

Mar 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1299
by: Bryan Olson | last post by:
I've run into a problem with Python/TkInter crashing, with an attempt to read illegal addresses, on Win on Win2000 and WinXP. With some web-searching, I found that people say not to manipulate...
2
5100
by: Zhang Le | last post by:
Hello, Is there a quick way to replace the content of a single item in tkinter's listbox? Currently my solution is to first delete the item, then insert a new item at the same position. I think...
0
1414
by: Svenn Bjerkem | last post by:
Hi, Armed with Programming Python 3rd Edition and Learning Python 2nd edition I try to write an application which I at first thought was simple, at least until I was finished with the GUI and...
32
7435
by: Kevin Walzer | last post by:
I'm a Tcl/Tk developer who has been working, slowly, at learning Python, in part because Python has better support for certain kinds of applications that I want to develop than Tcl/Tk does....
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.