In order to do this you need to connect callbacks to the figure. My program with an interactive matplotlib window does this in create_canvas (adapted from the same example tutorial from Gael that yours is).
Most of the callback setup from my program is very complicated and some of it overwrites matplotlib's default behavior which does the wrong thing, so I won't show it here -- but this is the basic idea; YMMV.
The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.
-- Roan LaPlante Athinoula A. Martinos Center for Biomedical Imaging