Polling selections from a listbox (Tkinter)

Discussion in 'Python' started by Harlin Seritt, Feb 26, 2005.

  1. 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
     
    Harlin Seritt, Feb 26, 2005
    #1
    1. Advertising

  2. Harlin Seritt

    Eric Brunel Guest

    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+-"])'
     
    Eric Brunel, Feb 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bill yeager

    multiple listbox selections

    bill yeager, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    461
    bill yeager
    Aug 12, 2003
  2. =?Utf-8?B?QWRpcw==?=
    Replies:
    0
    Views:
    393
    =?Utf-8?B?QWRpcw==?=
    Oct 19, 2004
  3. zdrakec
    Replies:
    0
    Views:
    537
    zdrakec
    Jul 22, 2005
  4. zdrakec
    Replies:
    0
    Views:
    478
    zdrakec
    Jul 22, 2005
  5. Chris Kettenbach

    asp:ListBox multiple selections

    Chris Kettenbach, Oct 7, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    10,345
    S. Justin Gengo
    Oct 7, 2005
Loading...

Share This Page