Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Perl Tk - Go back to main window from the child window

by priyaviswam (Sexton)
on Aug 05, 2011 at 08:58 UTC ( #918705=perlquestion: print w/replies, xml ) Need Help??
priyaviswam has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, Im in need of the clarification regarding whether we can go back to a main window from child window. For instance: I have a window named "menu" with options called fruits, vegetable. once I click on the button fruits, it will create a new window. Now If i want to go back to the main window "menu" using button event "Back to menu", what should i do? currently, Im deleting the main window instance once the the sub function "fruits" is called. Again from the Back button im calling the main window sub function which will create a new main window.Is this ok? or is there any other possibility?.

  • Comment on Perl Tk - Go back to main window from the child window

Replies are listed 'Best First'.
Re: Perl Tk - Go back to main window from the child window
by moritz (Cardinal) on Aug 05, 2011 at 09:16 UTC

    I'd prefer hiding and then showing again over destroying and reconstructing; it's probably faster, and preserves state (such as when the user resized or moved the window).

      Thanks for your sugestion.

Re: Perl Tk - Go back to main window from the child window
by zentara (Archbishop) on Aug 05, 2011 at 15:05 UTC
    I think all you need is withdraw, deiconify, and raise.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $top = $mw->Toplevel(); $top->configure(-title=>'Fruit Menu'); my $ls_show_fruit = $top->Scrolled('Listbox', -relief=>'groove', -width=>'20', -height=>5, -scrollbars=>'se' , -selectmode =>'single' )->pack(-side=>'left',-anchor=>'sw'); $ls_show_fruit->insert('end',"apples"); $ls_show_fruit->insert('end',"oranges"); $ls_show_fruit->insert('end',"peaches"); $top->Button(-text => 'Ok', -command => sub{ $top->withdraw; $mw->deiconify; $mw->raise; })->pack(); $top->withdraw; $mw->Button(-text=> 'select_fruit', -command => sub{ $top->deiconify; $top->raise; $mw->withdraw; })->pack; MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Perl Tk - Go back to main window from the child window
by Anonymous Monk on Aug 05, 2011 at 09:27 UTC

    Again from the Back button

    A back button suggests you might want to use Tk::Wizard

      I'll look into this option as well.Thanks for your suggestion

Re: Perl Tk - Go back to main window from the child window
by bart (Canon) on Aug 05, 2011 at 11:06 UTC
    Since you hide the main window when you show the child window, I wonder if it wouldn't be less consusing for the user if you showed the contents for both in the same physical window. So you'd hide the contents of the main window when you show the contents of the child window, and vice versa.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://918705]
Approved by moritz
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-01-21 21:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (230 votes). Check out past polls.

    Notices?