Bloodelf has asked for the wisdom of the Perl Monks concerning the following question:

I'm using TK and I need to change the -text value of a button that has been clicked.
i.e. If the button text is DISCONNECTED, I need it to say CONNECTED after a click.
Many thanks.

Replies are listed 'Best First'.
Re: TK Button modification
by kwoff (Friar) on Nov 14, 2001 at 05:02 UTC
    Here's an example:
    #!/usr/local/bin/perl -w use Tk; use strict; my $mw = MainWindow->new(); my $button = $mw->Button(); $button->configure(-text => 'DISCONNECTED', -command => sub { do_connect($button) }); $button->pack(); MainLoop(); sub do_connect { my $button = shift; $button->configure(-text => 'CONNECTED'); }

    FYI: there's a nice newsgroup devoted to Perl/Tk!

(ichimunki) Re: TK Button modification
by ichimunki (Priest) on Nov 14, 2001 at 04:59 UTC
    $button->configure( '-text', 'CONNECTED');

    Put that somewhere inside your callback for the action that gets taken when the button is clicked.
      Nice one!