#!/usr/bin/perl use Tk; my $mw = tkinit; $mw->withdraw; # hide the empty mainwindow my $filename = $mw->getOpenFile(); # or # my $filename1 = $mw->getSaveFile(); #if you want a filename for reading or writing respectively. print "$filename\n"; use Tk::Event qw(DONT_WAIT); #MainLoop; #### #!/usr/bin/perl # untested my $old = *{Tk::MainLoop}{CODE}; *Tk::MainLoop = sub { ... }; #Or use DoOneEvent() instead of MainLoop(), #to run only one event loop at a time. #An even better idea would be to look at #the test suite for Tk, and see how they handled it... #### #!/usr/bin/perl # by joost of perlmonks , original node number lost use Tk::Event qw(DONT_WAIT); while (1) { if ($self->run) { # test if we need to process $self->process_a_bit() # process a tiny bit } return if $self->quit; # test if quit status was set DoOneEvent(DONT_WAIT); # do normal Tk event select undef,undef,undef,0.0001; # wait for a bit } # I did this, because my processing was not easily adjusted # into the normal Tk::Eventloop processing and it needed to # be called a lot ("live" 44Kz audio stream processing, # with 100 samples per process_a_bit call) # If you want to go this route, you want to adjust the timing # of the select() and process_a_bit() calls until your GUI # and processing run fast enough, and it doesn't lock up # the whole machine when there is no processing being done :-) # Alternatively, if you're able to run your processing based # on file events or signals, you can take a look at the # Tk::Eventloop documentation for registering extra events # in the normal MainLoop.