[Tkinter-discuss] Event debugger

Michael Lange klappnase at web.de
Mon Jan 5 13:00:08 CET 2015

Hi Vasilis,

On Mon, 5 Jan 2015 10:44:22 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch> wrote:

> Happy new year Mattias,
> Is it possible to use xev to monitor another window's events?

you can use this simple technique for that:

import Tkinter
from subprocess import Popen, PIPE
import fcntl
import os

root = Tkinter.Tk()

p = Popen(('xev', '-id', str(root.winfo_id())), stdout=PIPE)
fcntl.fcntl(p.stdout.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)

def poll_events():
        out = p.stdout.read()
        print out
    except IOError:
    root.after(100, poll_events)
root.after(100, poll_events)

Unfortunately however, this way xev does *not* report mouse button
events, probably because of the limitation described at
http://www.rahul.net/kenton/events.html#LimitationsOf :

"Limitations of xev

Unfortunately, xev is not fool proof if you ask it to track events on a
window it does not own (the -id mode). It receives these events by
requesting them with Xlib's XSelectInput() function. This technique has
three major limitations:

    grabs - If one client activates a server, pointer, or keyboard grab,
then event reporting to all other clients will be affected. xev will not
be able to report some (or all) events, even though the client activating
the grab may be receiving them.

   non-maskable events - The X protocol does
not allow certain events to be reported to clients other than the one
that created the event window. Most of these events deal with selections.

   redirection events - The X protocol allows only one client to request
certain events. xev cannot receive these if another client is receiving
them. These events include window manager redirection events (e.g.,
substructure notify on the root window) and implicit passive grab events
(e.g., mouse button presses). 

Users of xev must find alternate techniques for studying the above areas.
The xscope and xmon programs, discussed in the next section, may be
helpful. "

A happy new year to all of you, and best regards


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Live long and prosper.
		-- Spock, "Amok Time", stardate 3372.7

More information about the Tkinter-discuss mailing list