Tkx: Is it possible to change a button's callback during execution

34 views Asked by At

As a really simplistic example, suppose I have a single button and each time I click the button I want it to call a different callback. So, it is first set up to call hello(), then hello() changes things so the next time the button is clicked it calls world().

1

There are 1 answers

0
Colin Wu On

RTFM!!!

Turns out any of the attributes of a widget can be changed with the 'configure' method:

...
$btn = $frame->$new_ttk__button(-text => "hello", -command => \&say_hello());
Tkx::MainLoop();

sub somefunc_invoked_by_some_other_button {
  $btn->configure(-text => "goodbye", -command => \&say_bye());
}