Your main window's event loop isn't started until line 25 is executed in your main routine, so events are not processed until after you've already executed line 24 and printed out the value. BTW, global variables are evil and should be avoided at all costs...