Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Refresh windows in Perl TK

by Anonymous Monk
on Oct 23, 2008 at 12:43 UTC ( [id://719032]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am new to Perl Tk programming. I am having the below mentioned problem.
There are few windows in my standalone application (developed in Perl Tk) All of them contains Refresh button individually (Functionality is already implemented).
Now I am trying to generalize this functionality in such a fashion that on selection of Refresh from the dropdown menu (In Main App) should refresh all the windows that are opened.
Please give me your valuable suggestions on how to implementing the same.

Replies are listed 'Best First'.
Re: Refresh windows in Perl TK
by zentara (Archbishop) on Oct 23, 2008 at 13:17 UTC
    You really need to show some code, but in general, windows should update themselves automatically. If your code is setup so that it dosn't update itself, there are a few things you can use:

    A timer

    my $repeater = $mw->repeat(1000, sub{ #repeats every second (1000 ms) &refreshing_sub1; &refreshing_sub2; #etc etc $mw->update; }); #later $repeater->cancel; #to stop it
    But you really need to show some example code. There are all sorts of builtin Tk methods for auto-updating, ranging from fileevent callbacks, to tied textvariables for the various widgets. If you are doing something like making a socket connection, or running something like a cron job, a timer should do it.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      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
        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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://719032]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found