Link a subroutine with a button action : Button « GUI « Perl






Link a subroutine with a button action

 

#!/usr/local/bin/perl -w
use Tk;
use strict;

my %info;

my $mw = MainWindow->new;
$mw->title("Data Entry");
my $f = $mw->Frame->pack(-side => 'bottom');
$f->Button(-text => "Exit", 
           -command => sub { exit; })->pack(-side => 'left');
$f->Button(-text => "Save",
           -command => sub {
            print "asdf";
          })->pack(-side => 'bottom');

MainLoop;

   
  








Related examples in the same category

1.Your first Perl/Tk program
2.Adding button (control) to a window
3.Pass subroutine to button and get called when clicking
4.Pass value to a subroutine in button action
5.Set Button action command
6.Load and save text file