[Tutor] Binding the mouse to a list using Tk.
andy surany
mongo57a@comcast.net
Mon, 14 Oct 2002 14:19:33 -0400
This is a multi-part message in MIME format.
--Boundary_(ID_rP+Enm3/pQR2u7Cqxy1VAQ)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
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)
--Boundary_(ID_rP+Enm3/pQR2u7Cqxy1VAQ)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2><FONT face=Arial size=2>
<P>Hi all!</P>
<P>What I want to do is use a button to capture the position/value of the</P>
<P>selected item in a scrolled list. So the user selects the item in the
list</P>
<P>with a single click of the left mouse button and then clicks a button.</P>
<P>Should be easy - I'm just not getting it......</P>
<P> </P>
<P>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list which
works fine. Created</P>
<P>another class (aaaaa) which populates the list - and it works fine.
Created</P>
<P>a handler under ScrolledList (handleList) which should trap the results
of</P>
<P>the bind (makeWidgets). Right now, all I'm trying to do is just print out</P>
<P>the value (just testing..) - but my logic is incorrect (actually, I think</P>
<P>that the logic may be correct - it's just in the wrong place...).</P>
<P>Here is a synopsis of the code. The "...." is non-relevant code which I have
removed for simplification.</P>
<P> </P>
<P>class ScrolledList(Frame):</P>
<P> def __init__(self, options, parent=None):</P>
<P> ........</P>
<P> self.makeWidgets(options)</P>
<P> def handleList(self, event):</P>
<P> index = self.listbox.curselection()</P>
<P> label = self.listbox.get(index)</P>
<P> print "label is ", label</P>
<P> def makeWidgets(self, options):</P>
<P> ........</P>
<P> list.bind('<Button-1>',
self.handleList) </P>
<P>Class aaaaa</P>
<P> def update_strategy_code(self):</P>
<P> ..........</P>
<P> ScrolledList(options)</P>
<P> Button(self, text='Update',</P>
<P>
command=self.edit_strategy_code).pack(side=LEFT)</P>
<P> def edit_strategy_code(self):</P>
<P> label=self.listbox.get(ACTIVE)</P>
<P> print 'info2=',label</P>
<P> TIA!</P>
<P>Andy (mongo57a@comcast.net)</P></FONT></FONT></DIV></BODY></HTML>
--Boundary_(ID_rP+Enm3/pQR2u7Cqxy1VAQ)--