Perl TK multiple commands on a single button

329 Views Asked by At

I would like to do is to have a button to close my window (button_window), but also call a function (user_info):

my $btn = $main -> Button (-text => 'Start',
-command => sub {$button_window -> destroy},
-command => \&user_info)
-> pack ();

its executing only the last command thanks in advance

1

There are 1 best solutions below

0
Ștefan On BEST ANSWER

The sub can take any number of calls to other subs.

my $btn = $main->Button(
    -text    => 'Start',
    -command => sub {
        user_info();
        # do something else...
        $button_window->destroy;
    },
)->pack();

It's executing only the last command because a hash parameter can have only one '-command' key, so is overwritten.