Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A Tkinter widget wrapper around Listbox & the python list object

31 views
Skip to first unread message

David Ascher

unread,
Nov 4, 1995, 3:00:00 AM11/4/95
to
If anyone is interested, I've built a wrapper around the Tkinter
Listbox widget (with scrollbar, of course) and the UserList class.
This makes manipulation of the data in a listbox trivial -- just use
the standard python list manipulation commands.

As an example:

a = TkList(['spam', 'camembert', 'camelot'])
a.pack()
a = a + [{'guido':'god'}] # e.g. you can store any object
a.append([Tkinter.Button]) # not a mistake - it uses str() for display,
a = a*2 # also not a mistake, although not very useful =)
a = a[:-2]
a.sort()
a.reverse()

I've also included demo code at the end of the module, but note that
it requires another file, TkUtil.py, available in the same place.

http://maigret.cog.brown.edu/python/Tk/TkList.py

--
Brown University Box 1978 Providence RI 02912
Department of Cognitive and Linguistic Sciences
David_...@Brown.EDU (401) 863-3926

Guido van Rossum

unread,
Nov 6, 1995, 3:00:00 AM11/6/95
to
> If anyone is interested, I've built a wrapper around the Tkinter
> Listbox widget (with scrollbar, of course) and the UserList class.
> This makes manipulation of the data in a listbox trivial -- just use
> the standard python list manipulation commands.

Cool!

> a = a + [{'guido':'god'}] # e.g. you can store any object

> a = a*2 # also not a mistake, although not very useful =)
> a = a[:-2]

I'm not sure these operations should be implemented. For most other
sequence types, these three operations (+, * and [:]) yield *new*
objects without changing their operands. You make them modify the
first operands. What if someone generalizes and does something like

b = a[:2]

and assumes that this somehow creates a new list?

Or what if I write

b = a + b

???

Operations that modify their argument in this fashion are better
expressed as methods, similar to append(), sort() and reverse().

--Guido van Rossum <gu...@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>

0 new messages