Good morning. I've had some production code in effect for a few years using TKX under ActiveState Perl, but had to move to Strawberry because of Windows 10 at work. I'm now using Tk and have a problem. Under TKx, it was easy to change the botton's background color, but under Tk, I'm not seeing how. The background =>"yellow" did not work. Here's my code:
#!/usr/bin/perl -w use Tk; open(OUTFILE, '>>forecast.txt') or die "Cannot open forecast.txt: $!"; my $mw = MainWindow->new; $mw->geometry("150x700"); $mw->title("Multiple Windows Test"); my $button1 = $mw->Button(-text => "18-Letters", -command => sub {print OUTFILE "18L\n", back +ground => "yellow"})->pack(-side => "top"); my $button2 = $mw->Button(-text => "07-Orders", -command => sub {print OUTFILE "07O\n"})->pa +ck(-side => "top"); my $button3 = $mw->Button(-text => "36-Letters", -command => sub {print OUTFILE "36L\n"})->pa +ck(-side => "top"); my $button4 = $mw->Button(-text => "38-Letters", -command => sub {print OUTFILE "38L\n"})->pa +ck(-side => "top"); my $button5 = $mw->Button(-text => "11-Orders", -command => sub {print OUTFILE "11O\n"})->pa +ck(-side => "top"); my $button6 = $mw->Button(-text => "99-Letters", -command => sub {print OUTFILE "99L\n"})->pa +ck(-side => "top"); my $button7 = $mw->Button(-text => "21-Letters", -command => sub {print OUTFILE "21L\n"})->pa +ck(-side => "top"); my $button8 = $mw->Button(-text => "23-Letters", -command => sub {print OUTFILE "23L\n"})->pa +ck(-side => "top"); my $button9 = $mw->Button(-text => "Return to L&I", -command => sub {print OUTFILE "OOO\n"})->pa +ck(-side => "top"); my $button10 = $mw->Button(-text => "D1008235", -command => sub {print OUTFILE "D1008235 08\ +n"})->pack(-side => "top"); my $button11 = $mw->Button(-text => "D2008235", -command => sub {print OUTFILE "D2008235 08\ +n"})->pack(-side => "top"); my $button12 = $mw->Button(-text => "D2108235", -command => sub {print OUTFILE "D2108235 08\ +n"})->pack(-side => "top"); my $button13 = $mw->Button(-text => "D2208235", -command => sub {print OUTFILE "D2208235 08\ +n"})->pack(-side => "top"); my $button14 = $mw->Button(-text => "D2608235", -command => sub {print OUTFILE "D2608235 08\ +n"})->pack(-side => "top"); my $button15 = $mw->Button(-text => "D6108 CMPRT09", -command => sub {print OUTFILE "D6108235-1\n +"})->pack(-side => "top"); my $button16 = $mw->Button(-text => "D6108 CMPRT10", -command => sub {print OUTFILE "D6108235-2\n +"})->pack(-side => "top"); my $button17 = $mw->Button(-text => "D6308 CMPRT03", -command => sub {print OUTFILE "D6308235-1\n +"})->pack(-side => "top"); my $button18 = $mw->Button(-text => "D6408235 CMPRT03", -command => sub {print OUTFILE "D6408235-1\n +"})->pack(-side => "top"); my $button19 = $mw->Button(-text => "D6608 CMPRT06", -command => sub {print OUTFILE "D6608235-06\ +n"})->pack(-side => "top"); my $button20 = $mw->Button(-text => "D6608 CMPRT25", -command => sub {print OUTFILE "D6608235-25\ +n"})->pack(-side => "top"); my $button21 = $mw->Button(-text => "D6608 CMPRT26", -command => sub {print OUTFILE "D6608235-26\ +n"})->pack(-side => "top"); my $button22 = $mw->Button(-text => "D6608 CMPRT27", -command => sub {print OUTFILE "D6608235-27\ +n"})->pack(-side => "top"); my $button23 = $mw->Button(-text => "X6108235", -command => sub {print OUTFILE "X6108235 08\ +n"})->pack(-side => "top"); my $button25 = $mw->Button(-text => "D8815235", -command => sub {print OUTFILE "D8815235 15\ +n"})->pack(-side => "top"); my $button26 = $mw->Button(-text => "M1915235", -command => sub {print OUTFILE "M1915235 15\ +n"})->pack(-side => "top"); my $button27 = $mw->Button(-text => "M9015235", -command => sub {print OUTFILE "M9015235 15\ +n"})->pack(-side => "top"); my $button28 = $mw->Button(-text => "M9115235", -command => sub {print OUTFILE "M9115235 15\ +n"})->pack(-side => "top"); my $button29 = $mw->Button(-text => "WR115235", -command => sub {print OUTFILE "WR115235 15\ +nWR415235 15\n"})->pack(-side => "top"); $mw->Button(-text => "Exit", -command => sub{$mw->destroy})->pack(); MainLoop;

In reply to Change button color with Tk by PerlCowboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.