Event handling for several windows

I have a program that uses matplotlib to plot two images.

    > figim24 = figure(figsize=(5,5)) figim70 =
    > figure(figsize=(5,5))

    > I want an event loop that will be able to register which of
    > the two figures I mouse click in. When I only had one
    > figure I used

    > figim24.canvas.mpl_connect("button_press_event",clicker)

    > but that obviously only register events in figim24. Can
    > anyone guide me in the right direction for doing this?

You can either register two different callbacks (func1 and func2
below) or you can register both figures to the same callback (funcboth
below) and check which figure generated the event by inspecting the
figure.inaxes.figure attribute. The latter approach only works if you
click over an axes,

from pylab import figure, show

fig1 = figure()
fig2 = figure()

ax1 = fig1.add_subplot(111)
ax2 = fig2.add_subplot(111)

def func1(event):
    print 'func1'

def func2(event):
    print 'func2'

def funcboth(event):
    if event.inaxes is None: return
    if event.inaxes.figure==fig1:
        print 'funcboth: 1'
    elif event.inaxes.figure==fig2:
        print 'funcboth: 2'

fig1.canvas.mpl_connect('button_press_event', func1)
fig2.canvas.mpl_connect('button_press_event', func2)

fig1.canvas.mpl_connect('button_press_event', funcboth)
fig2.canvas.mpl_connect('button_press_event', funcboth)

show()