#!/usr/bin/perl use Tk; use strict; use warnings; my $mw = MainWindow -> new; my $frameSetUp = $mw -> Frame() -> pack( -side => 'top', -fill => "both", -expand => 1); my $startLoopButton = $frameSetUp -> Button( -text => 'Start', -command => \&startLoop ) -> pack( -side => 'left', -ipadx => 10, -fill => "both", -expand => 0); my $endLoopButton = $frameSetUp -> Button( -text => 'Abort', -command => \&interruptLoop ) -> pack( -side => 'left', -ipadx => 10, -fill => "both", -expand => 0); my $quitProgramButton = $frameSetUp -> Button( -text => 'Quit', -command => \&quitProgram ) -> pack( -side => 'left', -ipadx => 10, -fill => "both", -expand => 0); MainLoop; sub startLoop { while (1) { sleep (2); print STDERR "startLoop: still sleeping\n"; $mw -> update(); } } sub interruptLoop { #something to interrupt startLoop and return to MainLoop? print STDERR "I've been pressed\n"; die "but startLoop keeps running...\n\n"; } sub quitProgram { exit; } sub Tk::Error { my ($widget,$error,@locations) = @_; print STDERR "ERROR: $error\n"; }