use strict;
use Tk;
use Win32::Sound;
my $sound="tada.wav";
my $timer_id;
my $mw=new MainWindow();
my %row1=(-side=>'left',-pady=>10,-padx=>10);
my %row2=(-side=>'bottom',-pady=>10,-padx=>10);
my $b5=$mw->Button(-text => "EXIT", -command => sub {exit})->pack( %row2 );
my $b1=$mw->Button(-text => "play", -command => \&start_sound)->pack( %row1 );
my $b2=$mw->Button(-text => "stop", -command => \&stop_sound)->pack( %row1 );
my $b3=$mw->Button(-text => "start timer", -command => \&timer_on)->pack( %row1 );
my $b4=$mw->Button(-text => "stop timer", -command => \&timer_off)->pack( %row1 );
MainLoop();
sub start_sound()
{
Win32::Sound::Volume('100%');
Win32::Sound::Play("tada.wav",SND_ASYNC);
}
sub stop_sound()
{
Win32::Sound::Stop();
}
sub timer_on()
{
if (! defined $timer_id)
{
$timer_id=$mw->repeat(1200,\&start_sound);
}
}
sub timer_off()
{
if (defined $timer_id)
{
$timer_id->cancel;
undef($timer_id);
}
}