in reply to Re: Refresh windows in Perl TK
in thread Refresh windows in Perl TK

Hi I am planing to refresh the window according the value selected in the option window. The code is ################### use Tk; @cm_tools = ("CVS", "VSS", "PVCS", "RCS", "Start Team"); $mw = MainWindow->new(); #$mw->geometry("300x200"); $mw->title("ZenSOFT Configuration Tool"); $mw->Label(-text => "Top", -background => "red")->pack(); $mw->Label(-text=>"CM Tool")-> pack(-expand => '1'); $mw->Optionmenu(-options=>@cm_tools,-textvariable=>\$cm_tool,-width=>'25')->pack(-expand => '1'); if ($cm_tool eq "VSS") { @fruits = ('Apple','Banana','Cherry','Date','Elderberry','Fig'); $fruit_list = $mw->Listbox(); for (@fruits) { $fruit_list -> insert('end',$_); } $fruit_list->pack(); } else { @fruits = ('Apple','Banana'); $fruit_list = $mw->Listbox(); for (@fruits) { $fruit_list -> insert('end',$_); } $fruit_list->pack(); } $EndFrame= $mw ->Frame(-width => '40')->pack(-side => "bottom"); $OkButton = $EndFrame->Button(-text => "Next", -width=>'10', -command => sub{$mw->destroy()})->pack(-padx=>'10',-pady=>'5', -side=>'left'); $CancelButton = $EndFrame->Button(-text => "Cancel", -width=>'10', -command => sub {exit })->pack(-padx=>'10',-pady=>'5', -side=>'right'); MainLoop(); ####################### In the above example i want to refresh the list according to the value selected in the option, in the same window. I am not planning to open new Tk window. Can you please me for the above problem or give me any best way to achieve this

Replies are listed 'Best First'.
Re^3: Refresh windows in Perl TK
by zentara (Cardinal) on Oct 24, 2008 at 16:03 UTC
    Hi, read the help files here at perlmonks on posting and wrapping your code in code tags, so its easier for us to read. Anyways, here is the best way to do what you want. You had some errors, and remember, always use warnings and use strict. In your case, I use the -listvariable option of the Listbox widget, to automatically change the array shown.
    #!/usr/bin/perl use warnings; use strict; use Tk; my @cm_tools = ( "CVS", "VSS", "PVCS", "RCS", "Start Team" ); my $mw = MainWindow->new(); $mw->title("ZenSOFT Configuration Tool"); $mw->Label(-text => "Top", -background => "red")->pack(); $mw->Label(-text=>"CM Tool")-> pack(-expand => '1'); my @fruits0 = ('Apple','Banana','Cherry','Date','Elderberry','Fig'); my @fruits1 = ('Apple','Banana'); my @fruits = @fruits1; my $cm_tool = 'CVS'; $mw->Optionmenu( -options=> \@cm_tools, -textvariable=>\$cm_tool, -width=>'25', -command => sub{ #print "$cm_tool\n"; if( $cm_tool eq 'VSS'){ @fruits = @fruits0 } else{ @fruits = @fruits1 } }, )->pack(-expand => '1'); my $fruit_list = $mw->Listbox( -listvariable => \@fruits, )->pack();; my $EndFrame= $mw ->Frame(-width => '40')->pack(-side => "bottom"); my $OkButton = $EndFrame->Button(-text => "Next", -width=>'10', -command => sub{$mw->destroy()})->pack(-padx=>'10',-pady=>'5', -s +ide=>'left'); my $CancelButton = $EndFrame->Button(-text => "Cancel", -width=>'10', -command => sub {exit })->pack(-padx=>'10',-pady=>'5', -side=>'ri +ght'); MainLoop();

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Thanks for the help.....
      I want to refresh the current window. i.e. according to the value selected by the option (VSS, CVS, etc..) the display name and the value of the field as to change from VSS to CVS in the same window.
      Ex:-
      $LoginFrame->Label(-text=>"VSS File Path")-> pack(-expand => '1');
      $LoginBox = $LoginFrame->Entry(-textvariable=>\$vss_path,-width=>'25')->pack(-expand => '1');
      to
      text = "CVS file path" and the variable to $cvs_path.
      Can it possible to acheive like this by using the Perl\Tk
        Yes you can do it. You can either set the refresh manually in some callback, or use the textvariable option. Just set $vss_path to whatever you want, and the Entry will automatically update. Otherwise, show a full working snippet and say what you want. Here is a clue on how to do it, you need to bind to the double click( or right-click) in the Listbox.

        I'm not really a human, but I play one on earth Remember How Lucky You Are