Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Polling selections from a listbox (Tkinter)

Reply
Thread Tools

Polling selections from a listbox (Tkinter)

 
 
Harlin Seritt
Guest
Posts: n/a
 
      02-26-2005
I am trying to poll selections from a listbox but can't seem to get it
to work correctly.

class pollstuff:
def __init__(self, master):
self.listbox = Listbox(master)
self.listbox.pack()

names = ['Bob', 'Neal', 'Mike']
for n in names:
self.listbox.insert(END, n)
self.listbox.select_set(0)

LabelStr = StringVar()
self.label = Label(master, textvariable=LabelStr)
self.label.pack()
LabelStr.set(names[map(int, self.listbox.curselection())])

root = Tk()
app = pollstuff(root)
root.mainloop()

Obviously when this starts up this is going to show selection #0 inside
the label box. How do I make sure that whatever is arbitrarily selected
ends up in the label box as this gui runs? I tried doing a bind:

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

This did not work as intended as the changelabel's text option only
showed what the selection index was BEFORE the event took place. Does
anyone know of any special thing I need to do in order to poll the
listbox items?

Thanks,

Harlin

 
Reply With Quote
 
 
 
 
Eric Brunel
Guest
Posts: n/a
 
      02-28-2005
On 26 Feb 2005 03:48:16 -0800, Harlin Seritt <> wrote:
[snip]
> Obviously when this starts up this is going to show selection #0 inside
> the label box. How do I make sure that whatever is arbitrarily selected
> ends up in the label box as this gui runs? I tried doing a bind:
>
> self.listbox.bind("<Button-1>", self.changelabel)
>
> This did not work as intended as the changelabel's text option only
> showed what the selection index was BEFORE the event took place.


Bind on <ButtonRelease-1>; <Button-1> is a synonym for <ButtonPress-1>, and when the button is pressed, the selection is not done yet.

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp:ListBox multiple selections Chris Kettenbach ASP .Net 5 10-07-2005 08:01 PM
Multi-select listbox losing selections - answered zdrakec ASP .Net 0 07-22-2005 09:33 PM
Multi-select listbox losing selections zdrakec ASP .Net 0 07-22-2005 07:51 PM
Obtaining Data Based Upon Multiple Selections From a ListBox... =?Utf-8?B?QWRpcw==?= ASP .Net 0 10-19-2004 01:29 PM
multiple listbox selections bill yeager ASP .Net 0 08-12-2003 08:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57