[Tkinter-discuss] Method calling upwards; Listbox arrow events ?
Vasilis Vlachoudis
Vasilis.Vlachoudis at cern.ch
Tue Jul 8 10:51:39 CEST 2008
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()
>
> --------------------------------------------------------
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Vasilis_Vlachoudis.vcf
Type: text/x-vcard
Size: 312 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20080708/669d60e1/attachment.vcf>
More information about the Tkinter-discuss
mailing list