11.8. How do I ring the bell?

The short answer is

   $widget -> bell;
A slightly longer answer might include a fully functioning script:
    #!/usr/bin/perl
    use Tk;
    $main = MainWindow -> new;
    $butn = $main->Button(-text => 'bell')
    $butn->configure(-command => sub{ $butn->bell; });
    $butn->pack();
    MainLoop;
An even longer answer would be a fully functioning script with a callback:
    #!/usr/bin/perl
    use Tk;
    $main = MainWindow -> new;
    $but = $main->Button(-text => 'bell', 
                         -command => sub{ringit($main)})->pack;
    MainLoop;
    
    sub ringit { 
        my $m = shift; 
        $m->bell; 
    }
Simon Galton <galtons@candu.aecl.ca> reminds us to be careful in that
some systems remap this [the "console bell"] to anything from a digital sound to a flash on the screen.

Previous | Return to table of contents | Next