Tkinter.Listbox: activate() doesn't work

Martin Franklin martin.franklin at westgeo.com
Thu Oct 25 04:03:01 EDT 2001


Theodore D. Sternberg wrote:

> How can I programmatically activate an element in a Tkinter.Listbox?
> I've tried activate() but nothing happens.  For example,
> 
> import Tkinter
> root=Tkinter.Tk()
> lb = Tkinter.Listbox(root)
> lb.insert( Tkinter.End, 'foo' )
> lb.insert( Tkinter.End, 'bar' )
> lb.pack()
> lb.activate( 1 )
> 
> ...but I don't see 'bar' now getting highlighted.  What am I doing wrong?
> 
> Ted Sternberg
> Berkeley, CA
> 



Ted,

Try the selection_set method:-


from Tkinter import *
root=Tk()
lb=Listbox(root)
lb.insert(0, 'thing')
lb.insert(0, 'another thing')\
lb.pack()
lb.selection_set(first=0)
root.mainloop()

Cheers,
Martin




More information about the Python-list mailing list