Hi, Everybody!

I've finally finished the Llama and have started on the Emu. I'm trying to make a simple Perl/Tk program that displays a grid of Checkbuttons. I want to call a subroutine when the buttons are checked/unchecked (same sub eitherway). Here's the code that works (works but without calling the sub):

#!perl use warnings; use strict; use Tk; my $mw = MainWindow->new; $mw->title("Checkbutton Grid"); my $x_size = 5; my $y_size = 5; my %b_name; for (my $x=0; $x<$x_size; ++$x) { for (my $y=0; $y<$y_size; ++$y) { $mw -> Checkbutton ( -activebackground => "white", ) -> grid ( -row => $x, -column => $y ); } } MainLoop;

But this doesn't do what I expect it to:
$mw -> Checkbutton ( -activebackground => "white", -command => &react ("\"$x\_$y\""); -command => print "hi" # <= this is a change ) -> grid ( -row => $x, -column => $y ); .... sub react { print "$_[0]\n"; }

From the text it seems that when I check/uncheck a Checkbutton that the shell window should print the grid coordinates. Instead, when the script is run the 25 sets of coordinates go straight to the window and nothing happens when the Checkbuttons are checked/unchecked. What am I missing?

For a free bonus, if more-experienced-posters-than-I want to clue me in on the appropriate use of READMORE I'd be willing to learn! cog already instructed me on signatures ;)


UPDATE:pg has the code for what I was looking to do. The other blessed and beautiful monks who replied were all right, their answers match what the Emu says. I was wanting to be able to call a sub through -command and discovered how last night reading the source code for some of the examples in widget.exe. This (thanks, pg and widget.exe authors) is what does what I wanted to do:
-command => [\&display, $x, $y]

So, thanks everyone, for your part in my learning experience.

Cheers!
-P

Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
-Howard Aiken

In reply to Perl/Tk : Trouble with commands and Checkbuttons by Petras

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.