469,929 Members | 1,751 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Tkinter Event Types

Hi,
When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
print event.type

I see "7" printed out. Where are these constants defined for various
event types? Basically i want to do something like...

def callback(self, event):
if event.type == ENTER:
print "You entered"

thanks

Jul 19 '05 #1
3 3483
codecraig wrote:
Hi,
When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
print event.type

I see "7" printed out. Where are these constants defined for various
event types? Basically i want to do something like... 7 must be for KeyPressed.
That's the type of the event (among Activate, Button, KeyPressed...).

def callback(self, event):
if event.type == ENTER:
print "You entered"


You may want to look at event.keycode (36 for Return).

Jul 19 '05 #2
The "type" field is related to the definition of different events in
X11. In Xlib, the event structure is a "C" union with the first
(common) field giving the type of the event so that the event-dependant
fields can be accessed through the proper union member.

Generally, you won't use this field in Tkinter programs.

jeff

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

iD8DBQFCZFtQJd01MZaTXX0RAmffAJwPXtWUugiSVGukuqc27M ZWcrs2zACfZfH7
PRNDFDXbj+DH9Df2xQywnWg=
=2ryT
-----END PGP SIGNATURE-----

Jul 19 '05 #3
On 18 Apr 2005 13:48:50 -0700, codecraig <co*******@gmail.com> wrote:
Hi,
When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
print event.type

I see "7" printed out. Where are these constants defined for various
event types? Basically i want to do something like...

def callback(self, event):
if event.type == ENTER:
print "You entered"


The usual way is to bind different callbacks on different events. So you won't have to test the event type in your callback, since the callback itself will already have been selected from the event type. If you insist in doing it the way you mention, you can always do:
ENTER_EVENT = 1
KEYPRESS_EVENT = 2
# ...

def myCallback(evtType, evt):
if evtType == ENTER_EVENT:
# some action...
elif evtType == KEYPRESS_EVENT:
# some other action...
# ...

myWidget.bind('<Enter>', lambda evt: myCallback(ENTER_EVENT, evt))
myWidget.bind('<KeyPress>', lambda evt: myCallback(KEYPRESS_EVENT, evt))
I can't really see what it will be good for however...

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Adonis | last post: by
4 posts views Thread by Patrick L. Nolan | last post: by
6 posts views Thread by Elaine Jackson | last post: by
1 post views Thread by syed_saqib_ali | last post: by
2 posts views Thread by Grooooops | last post: by
2 posts views Thread by Kevin Walzer | last post: by
1 post views Thread by vigacmoe | last post: by
2 posts views Thread by Kevin Walzer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.