TKinter Listbox Question.

Matthew Dixon Cowles matt at mondoinfo.com
Mon Aug 14 18:24:55 EDT 2000


In article <8n8mq5$o51$1 at nnrp1.deja.com>, Huw Lynes
<hlynes at my-deja.com> wrote:

> Hi all,
> 
> I'm fairly new to python and have just started to play with TKinter.
> I'm trying to put some file browser capability into the program I am
> writing at the moment.
> I have my frame containg a listbox which displays the contents of the
> current directory and I can run a function when I select one of these.
> My question is if I select a directory and get a list of its contents,
> can I display that in the same listbox? If so how?
> Essentially I dont want to have to open a new frame every time I select
> something in the Listbox. Hope the above question actually makes sense.

Dear Huw,
Keith is certainly right that tkFileDialog is very useful. But you may
want to know an answer to your original question too.

If I understand your question correctly, you want to replace the
contents of a listbox with a new list of items. All you have to do is
delete the old items and add some new ones:

self.lb.delete(0, END) # clear
for item in myList:
  self.lb.insert(END, item)

I swiped that code pretty well directly from Fredrik Lundh's excellent
introdcution to Tkinter, which is at:

http://www.pythonware.com/library/tkinter/introduction/index.htm

If you haven't had a look at it, you may want to.

You might also want to have a look at Greg MacFarlaine's cool Pmw
(Python megawidgets):

http://www.dscpl.com.au/pmw/

His ScrolledListBox widget will save you a step here since it has a
setlist() method.

Regards,
Matt



More information about the Python-list mailing list