473,434 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

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 3901
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adonis | last post by:
I wish to manually move widgets in Tkinter, now I have successfully done it, but with odd results, I would like to move the widgets with a much smoother manner, and better precision. Any help is...
4
by: Patrick L. Nolan | last post by:
Our Tkinter application has a big ScrolledText widget which is a log of everything that happens. In order to prevent people from making changes, we have it in DISABLED mode except when the...
6
by: Elaine Jackson | last post by:
I've got a script where a button gets pushed over and over: to cut down on the carpal tunnel syndrome I'd like to have the button respond to presses of the Enter key as well as mouse clicks; can...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
2
by: Grooooops | last post by:
I've been hacking around this for a few days and have gotten close to what I want... but not quite... The TKinter Docs provide this example: # configure text tag text.tag_config("a",...
2
by: Kevin Walzer | last post by:
I'm trying to decide whether I need threads in my Tkinter application or not. My app is a front end to a command-line tool; it feeds commands to the command-line program, then reads its output and...
1
by: vigacmoe | last post by:
Hi all, I'm trying to write a simple tkinter program, then this problem popped up. The followin code will describe the problem. ------------------------------------------ import Tkinter ...
2
by: Kevin Walzer | last post by:
I'm porting a Tkinter application to wxPython and had a question about wxPython's event loop. The Tkinter app provides a GUI to a command-line tool. It gathers user input, and opens an...
1
by: Noah | last post by:
I'm trying to match against Event.type for KeyPress and ButtonPress. Currently I'm using integer constants (2 and 4). Are these constants defined anywhere? The docs talk about KeyPress and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.