Tkinter.Listbox: activate() doesn't work
John McMonagle
johnmc at velseis.com.au
Thu Oct 25 19:26:40 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?
>
>
You are doing nothing wrong at all - the activate method sets the
element specified by the given index as active when the listbox widget
has input focus. One way of setting the input focus is by tabbing to
the desired widget - try this and you will see the desired behaviour.
Note: an active element is not equivalent to a selected element. To
select elements you can use the selection_set method.
Regards,
John
More information about the Python-list
mailing list