I would think it should be possible to do this. In Tk, you can define a callback for on_click(), so if GTK2 works similarly, you could wrap that in a subroutine call that also sets your global variable. I'm afraid you're not being specific enough (which variable? set it to what?) for me to answer beyond that.