On Thu, 17 Mar 2005 12:56:33 -0500, BJ <[EMAIL PROTECTED]> wrote:
> Is it possible to change the selected value through software and have
> the results change on the screen? A very simple example would be if I
> had a form with optionmenu's that I was using for data entry, and I
> wanted to reset all the optionmenu's to their default value after the
> "submit" button is pressed. Is there a way that this can be done? Does
> anyone have a link to a good tutorial? The oreilly book on perl tk
> doesnt discuss this. Also, along the same path, does anyone have an
> exampke or a suggestion as to how I could have the options in one menu
> depend on the choice made in another? Thank you very much for your help.
> I tried to read teh manuals, but couldnt find what I was looking to do. ~BJ
> 

It sounds like you need to learn about callbacks and how to use them.
Basically, they are subroutines that you bind a widget to be "called
back" when an event that is related to that widget happens (e.g. a
button being pressed).
Since you have the Oreilly book, you should be fine - just start
reading at the beginning, everything you need to know is covered
there.
Meanwhile I took the example from the Tk::Optionmenu pod page
(http://search.cpan.org/dist/Tk/pod/Optionmenu.pod) and modified it by
adding a button that resets the option menu in the example. Hopefully
this will help you get started:
########### begin code ################
use Tk;
my $mw = MainWindow->new();

my ($var, $tvar);
my $opt = $mw->Optionmenu(
       -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]],
       -command => sub { print "got: ", shift, "\n" },
       -variable => \$var,
       -textvariable => \$tvar
      )->pack;

my $f = $mw->Frame(-relief=>'groove', -borderwidth => 2)->pack;
$f->Label(-textvariable=>\$tvar)->pack(-side => 'left');
$f->Label(-text => " -> ")->pack(-side => 'left');
$f->Label(-textvariable=>\$var)->pack(-side => 'left');

$mw->Button(-text=>'Done Selecting!', 
  -command=>sub{
     $var = 1; $tvar = "jan";
     $opt->configure(
       -variable => \$var,
       -textvariable => \$tvar
     );
  })->pack;
$mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack;

MainLoop;
########### end code ################

Hope this helps,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to