[Tutor] Bindings in Tkinter
Rick Pasotto
rickp@telocity.com
Wed, 29 May 2002 12:40:08 -0400
A couple of points but not necessarily a solution.
1) The window your code produces is too small to see. :-)
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>.
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