Search code examples
perlperl-moduleperltk

How to open and grab a window over TopLevel window


I want to open a window inside a toplevel window and until that window is opened I should not be able to move back to any previously opened window. Here is my code:

$mw = MainWindow->new; # This will make my main Window
$mw->title("Main Window");
$menubar = $mw->Menu;
$mw->configure(-menu =>  $menubar); 

$sub_window=$menubar->cascade(-label => 'Menu',-tearoff => 0);
$sub_window->command(-label => 'Sub_Menu_Window',-command=>\&Open_window);  # I've placed a sub menu which will open new window on main window.

sub Open_window
{
 $mw=shift;
 $new_wind =$mw->Toplevel(-title => "New Sub Window");
 $new_wind->grab;  #here i have opened a new window and I won't be able to go back to my main window unless I will close this because of grab.

 $new_wind ->Button(-text=>"another_window",-command =>\&AnotherWindow) ->pack();

    sub AnotherWindow
    {
                  # What Code Should I enter here to open a new window when I press button "another_window". ALso I want that until this window is closed I should not be able to work with other window previously opened.(Same as grab used with toplevel window)
    }

}
MainLoop;

I want to make this AnotherWindow same as like toplevel window, so that When I press the button and until that window will remain open, I can't work with any other opened window.


Solution

  • We can do like this:

    sub AnotherWindow
    {
        $window_over_top_level =$new_wind->Toplevel(-title => "Window Over Top Level With Grab");
    $window_over_top_level->geometry( "270x380");
    $window_over_top_level->grab;
    }