The best solution I found on the web to overcome the binding problem is to use the <<ListboxSelect>> event, which is called after a change in the selection of the list

self.list.bind("<<ListboxSelect>>", self.listChanged)

def listChanged(self, event):
   print "selection=",self.list.curselection()
gegard wrote:
I'm now trying to respond to listbox changes and have two problems
illustrated in the example below. The example's an extension of the one that
Cameron Laird supplied in a response earlier today.

1) How do I make things happen in the main loop when they do in an instance
of SListbox? SListbox.click() runs fine, but I just can't see how to call
methods in main. I'd thought that self.master might hold the keys (maybe
even literally), but I can't work that out.

2) Why can I not bind to arrow keys (Up in this example)? Arrow keys do not
change the list box and, presumably as a consequence, I can't get the
SListbox.uparrow() method to run.

As ever, thank you for direction.

Regards, Geoff

--------------------------------------------------------
import Tkinter

class SListbox(Tkinter.Frame):
    # Listbox in a frame, will be linked with other widgets
    def __init__(self, parent):
        Tkinter.Frame.__init__(self, parent)
        self.pack()
        self.list = Tkinter.Listbox(self)
        self.list.pack()
        self.list.bind('<ButtonRelease-1>', self.click)
        self.list.bind('<Up>', self.uparrow)

    def append(self, entry):
        self.list.insert(Tkinter.END, entry)

    def click(self, args=None) :
        # This method works, but I don't know how
        # to make it affect the main loop so that I can act on it
        print 'Clicked Selection', str(self.list.curselection())
        # self.master.... what now? I want to populate the text box.



    def uparrow(self, args=None) :
        # This method is never reached
        print 'Uparrow'
m = Tkinter.PanedWindow(orient = Tkinter.VERTICAL)
m.pack(fill = Tkinter.BOTH, expand = 1)
top = Tkinter.Label(m, text = "Do you see how wide the top pane is?")
m.add(top)
# New listbox in a frame
list = SListbox(m)
m.add(list)
text = Tkinter.Text(m)
m.add(text, height=20, width=10)
bottom = Tkinter.Label(m, text = "bottom pane")
m.add(bottom)

m.winfo_toplevel().title("look at me")
for entry in range(20):
    list.append("entry "+str(entry))
#Tkinter.mainloop()
--------------------------------------------------------

begin:vcard
fn:Vasilis Vlachoudis
n:Vlachoudis;Vasilis
org:CERN;AB
adr:CERN;;Dep.AB;Geneva-23;;CH-1211;Switzerland
email;internet:[EMAIL PROTECTED]
title:Dr
tel;work:+41-22-767.9851
tel;fax:+41-22-766.9644
tel;cell:+41-76-487.4378
x-mozilla-html:FALSE
url:http://home.cern.ch/bnv
version:2.1
end:vcard

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to