469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

bindings in Tkinter

I made a "notebook" script in Python and bind CTRL+N as next file. At
the first time it works well, but then it stops. I found, that I have to
release CTRL, when using this second time. Is there any solution so I do
not have to release CTRL and just keep pressing N,N,N,....

Thanks a lot
Pavel

Using Python 2.3 under W2k.
Jul 18 '05 #1
3 2079
The following program just fine for me, printing "Control-N"
multiple times without the need to release and re-press control each
time:
from Tkinter import Tk
t = Tk()
def puts(s): print s
t.bind("<Key-Control_L>", lambda e: puts("Control"))
t.bind("<Key-Control_R>", lambda e: puts("Control"))
t.bind("<KeyRelease-Control_L>", lambda e: puts("Released Control"))
t.bind("<KeyRelease-Control_R>", lambda e: puts("Released Control"))
t.bind("<Control-n>", lambda e: puts("Control-N"))
t.mainloop()

Your problem must be because you've done something more complicated than
you've told us. For instance, if your binding for <Control-n> creates
or destroys widgets, moves the input focus, etc., maybe something bad is
happening.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFAzam6Jd01MZaTXX0RAp6uAJ9iGCEk6rcOv7OWJip71C kEZg7JoACgrMwp
fHtcrQazgmh+2UNTsmMPvxk=
=IkkD
-----END PGP SIGNATURE-----

Jul 18 '05 #2
Solved.- I must have old documentation, I used '<Control_L>n'.
Thank you.
Pavel

Jeff Epler napsal(a):
The following program just fine for me, printing "Control-N"
multiple times without the need to release and re-press control each
time:
from Tkinter import Tk
t = Tk()
def puts(s): print s
t.bind("<Key-Control_L>", lambda e: puts("Control"))
t.bind("<Key-Control_R>", lambda e: puts("Control"))
t.bind("<KeyRelease-Control_L>", lambda e: puts("Released Control"))
t.bind("<KeyRelease-Control_R>", lambda e: puts("Released Control"))
t.bind("<Control-n>", lambda e: puts("Control-N"))
t.mainloop()

Your problem must be because you've done something more complicated than
you've told us. For instance, if your binding for <Control-n> creates
or destroys widgets, moves the input focus, etc., maybe something bad is
happening.

Jeff

Jul 18 '05 #3
On Wed, Jun 16, 2004 at 06:58:37AM +0200, p.kosina wrote:
Solved.- I must have old documentation, I used '<Control_L>n'.
Thank you.
Pavel


Aha!

The first argument to bind can be a sequence of events, which would
explain exactly the behavior you saw. This *can* be useful (it's in
effect how double-click works) but it can also do something different
than what you want.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFA0D48Jd01MZaTXX0RAsX7AKCpc4kDteZdymyEjOGuTU 8Y5FbITACcCjj7
xXvwMsGBYpBc60Id5PGuutE=
=kOTv
-----END PGP SIGNATURE-----

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Will Woods | last post: by
3 posts views Thread by Gabriel B. | last post: by
1 post views Thread by Arthur Chereau | last post: by
reply views Thread by mg | last post: by
12 posts views Thread by Thomas Bartkus | last post: by
1 post views Thread by Michael Yanowitz | last post: by
1 post views Thread by Jason Yamada-Hanff | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.