[Tkinter-discuss] Listbox selection issue

Michael Lange klappnase at web.de
Thu Apr 15 19:05:51 EDT 2004


On Thu, 15 Apr 2004 14:14:20 -0300
"Batista, Facundo" <FBatista at uniFON.com.ar> wrote:

> Hi,
> 
> I set up a ListBox. When it appears, it gets the first item selected. With
> selected I mean that its line is colored.
> 
> I want the user to have to double click to change the selection. So I binded
> double-click to a function. That's ok.
> 
> But I want that if the user just click in other item, that item don't get
> selected/colored. 
> 
> I implemented something this:
> 
>         self.listbox.bind("<Button-1>", self.noIr)
>         self.listbox.select_set(0)
>         ...
> 
>     def noIr(self, evento):
>         print self.listbox.curselection()
>         sel = self.listbox.curselection()
>         sel = int(sel[0])
>         self.listbox.select_set(sel)
>         print self.listbox.curselection()
>         return
> 
> 
> The prints are for debug only. With the second one, I see that the selection
> didn't change. but another item is colored!!
> 
> I think I'm have a terminology problem, please explain it to me if I'm
> wrong.
> 
> Thank you!
> 
> .	Facundo
> 

I havent't tried this, but it sounds like the "print self.listbox.curselection()" at the end of
your noIr() method doesn'treturn the item that is colored on the screen, maybe calling

self.listbox.update_idletasks()

at the end of noIr() would fix this; anyway, I think a method that would do what you actually want
might look like this:

        ...
        self.listbox.bind("<Button-1>", self.noIr)
        ...

    def noIr(self, evento):
	'''Dummy function to stop a mouse-click from selecting a listbox item.'''
        return "break"

I hope this helps

Michael



More information about the Tkinter-discuss mailing list