[Tutor] Bindings in Tkinter

shendric@arches.uga.edu shendric@arches.uga.edu
Wed, 29 May 2002 13:52:12 -0500


>A couple of points but not necessarily a solution.
>
>1) The window your code produces is too small to see. :-)

Yeah, since I was just testing it, I didn't bother to make it visible.  
Ah, well.
>
>2) The widget has to be active for the bindings to work so you can't
>bind to a widget that is completely covered by other widgets (or too
>small to make active using the mouse).
>
>3) Try some other binding. After some minor changes I got your code to
>work with <Button-1> but not with <Control-Shift-Up>.

Ok, so I changed the binding to <Button-1>, and made the frame bigger, 
and it works, but I still can't get it to work with any of the keystroke 
bindings, only the mouse.  Or, at least not with <Return>, the <F1>-<Fx> 
family, or <Control-Shift-Up>.  Seems odd to me.

Sean
>
>On Wed, May 29, 2002 at 10:56:24AM -0500, shendric@arches.uga.edu 
wrote:
>> Hello,
>> 
>> I'm having difficulty with bindings, but I'm not real sure what I'm 
>> doing wrong.  The following is a small bit of code that is part of a 

>> larger app that I'm working on.  The idea is to simply bind the 
>> <Control-Shift-Up> key to a little printing function, but it does 
>> nothing at all.
>> 
>> The larger app actually contains things within the frames that are 
>> created, but I left them out of this for convenience and brevity.
>> 
>> Any ideas?
>> 
>> Sean Hendricks
>> 
>> 
>> from Tkinter import *
>> import Pmw
>> 
>> class VTrans:
>> 	def __init__(self, master):
>> 		self.master = master
>> 		self.frame = Frame(master)
>> 		self.frame.top = Frame(master)
>> 		self.frame.bottom = Frame(master)
>> 		self.frame.top.pack(side=TOP, fill=X)
>> 		self.frame.bottom.pack(side=TOP)
>> 		self.frame.pack()
>> 		self.getBindings()
>> 
>> 	def doStuff(self, event=None):
>> 		print "I am the very model of a ..."
>> 
>> 	def getBindings(self):
>> 		self.frame.top.bind('<Control-Shift-Up>', self.doStuff)
>> 
>> if __name__ == "__main__":
>> 	root = Tk()
>> 	root.title('Test')
>> 	Pmw.initialise()
>> 	main = VTrans(root)
>> 	root.mainloop()
>
>-- 
>"Drawing on my fine command of language, I said nothing."
>		-- Mark Twain
>    Rick Pasotto    rickp@telocity.com    http://www.niof.net
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
---------End of Included Message----------