The sidebar entitled "Specifying arguments to callbacks" in Philipp Janert's article Using Advanced Widgets in Perl/Tk (IBM developerWorks) describes the difference in two methods of passing arguments to a -command option for a Tk widget-one fixing the options used at the time the constructor is first executed, the other taking the options at execution time. It may be worth your time to review.

Example code to display the effect

use strict; use warnings; use Tk; my $t = time; my $ts = update_time($t); my $mw = MainWindow->new(); my $label = $mw->Label( -textvariable => \$ts, ) ->grid( -row => 1, -column => 1, -columnspan => 3, ); my %button; # Fixed - will display time when button was created # Variable - will display current time $button{fixed} = $mw->Button( -text => q{Fixed}, -command => [ \&update_time, $t, ], )->grid( -row => 2, -column => 1, ); $button{variable} = $mw->Button( -text => q{Variable}, -command => sub { $t = time; &update_time( $t, ); }, )->grid( -row => 2, -column => 2, ); $button{exit} = $mw->Button( -text => q{Exit}, -command => sub { exit; }, )->grid( -row => 2, -column => 3, ); MainLoop; # subroutines sub update_time { my $ct = shift @_; $ts = sprintf qq{%s}, scalar localtime $ct; }

Hope that helps.


In reply to Re: Passing arguments for GUI development in Tk by atcroft
in thread Passing arguments for GUI development in Tk by archana12

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.