use Tk; use IO::Socket::INET; use threads; use strict; use warnings; $| ++; threads->create(\&a); my $mw = MainWindow->new(title => "window"); $mw->Button(text => "exit", command => sub {exit})->pack(); MainLoop; sub a { sleep(10000); }