in reply to perl tk MainLoop hangs

MainLoop waits for something to happen but in your example nothing will ever happen. If you add a button, you can see that the script is still responsive.

use strict; use warnings; use Tk; my $mw = new MainWindow(-background=>'Gray'); my $btn = $mw->Button( -text => "Exit", -command => sub { print "Button pressed\n"; } )->pack(); MainLoop;

UPDATE: In other words, you need to completely set up your application, GUI and response functions and then call MainLoop. MainLoop will watch the GUI and react to any user interaction by executing the provided callback functions.

If you knew this all already, then there must be a bug in your program elsewhere.