[Tutor] Binding the mouse to a list using Tk.

andy surany mongo57a@comcast.net
Mon, 14 Oct 2002 23:49:56 -0400


Thanks Dylan. I am using the listbox methods. And everything works. If I put
the list.bind in the same method that calls the scrolled list, I even get a
response when I move the cursor to list selection (listbox.cursorselection).
The problem is that I need the selected list item to be independent of the
mouse (mouse is depressing a button which gets the original highlighted list
item). It's almost like I'm losing context.

I haven't looked at getcurselection - which I will do now. I still think
that my logic is correct - but I haven't placed it in the correct spot.

Regards,

Andy
-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: tutor@python.org <tutor@python.org>
Date: Monday, October 14, 2002 6:59 PM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>    Only had a brief look at your problem, but I believe that the Tkinter
>widgets Listbox and ScrolledListBox may be what you need (and save you
quite
>a bit of time).  You can use the Listbox methods from within the
>ScrolledListbox object as well.  You could then possibly associate a
>function with your button which gets the currently selected item.
>getcurselection() returns the text while the curselection() will return the
>index.
>    A lot of this is quite similar to what your code has proposed but using
>the built-in widgets and their functions may shed some light on an easier
>solution.
>
>    HTH,
>        Dylan
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Tuesday, 15 October 2002 04:20
>To: tutor@python.org
>Subject: [Tutor] Binding the mouse to a list using Tk.
>
>
>Hi all!
>
>What I want to do is use a button to capture the position/value of the
>
>selected item in a scrolled list. So the user selects the item in the list
>
>with a single click of the left mouse button and then clicks a button.
>
>Should be easy - I'm just not getting it......
>
>
>
>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>which works fine. Created
>
>another class (aaaaa) which populates the list - and it works fine. Created
>
>a handler under ScrolledList (handleList) which should trap the results of
>
>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>
>the value (just testing..) - but my logic is incorrect (actually, I think
>
>that the logic may be correct - it's just in the wrong place...).
>
>Here is a synopsis of the code. The "...." is non-relevant code which I
have
>removed for simplification.
>
>
>
>class ScrolledList(Frame):
>
>    def __init__(self, options, parent=None):
>
>        ........
>
>        self.makeWidgets(options)
>
>    def handleList(self, event):
>
>        index = self.listbox.curselection()
>
>        label = self.listbox.get(index)
>
>        print "label is ", label
>
>    def makeWidgets(self, options):
>
>        ........
>
>        list.bind('<Button-1>', self.handleList)
>
>Class aaaaa
>
>    def update_strategy_code(self):
>
>        ..........
>
>        ScrolledList(options)
>
>        Button(self, text='Update',
>
>        command=self.edit_strategy_code).pack(side=LEFT)
>
>    def edit_strategy_code(self):
>
>        label=self.listbox.get(ACTIVE)
>
>        print 'info2=',label
>
> TIA!
>
>Andy (mongo57a@comcast.net)
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor