in reply to Change button color with Tk

PerlCowboy:

I think it's because you need to change:

my $button1 = $mw->Button(-text => "18-Letters", -command => sub {print OUTFILE "18L\n", back +ground => "yellow"})->pack(-side =>"top");

to this:

my $button1 = $mw->Button(-text => "18-Letters", -command => sub {print OUTFILE "18L\n" }, -background => "yellow"})->pack(-side =>"top +");

I don't use Tk or Tkx, but it seems to me that:

sub { print OUTFILE "18L\n", background => "yellow" }

Can't possibly do what you're expecting. The print statement doesn't know anything about colors. In fact, the code is essentially equal to:

sub { print OUTFILE "18L\n", "background", "yellow" }

So if you look at the file you're printing to, I'd expect you'll see some unexpected "backgroundyellow" strings in there.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Change button color with Tk
by PerlCowboy (Novice) on Nov 01, 2017 at 17:26 UTC
    This got me a little farther, but now I need to call the subroutine when the button is clicked.
    my $button1 = $mw->Button(-text => "18-Letters", -command => sub {print OUTFILE "18L\n",\&onclick,} ,) ->pack(-side => "top"); sub onclick{ $button1->configure(-background=>"yellow") }