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

I have a main application and dialog windows created with my $dialog = $mw->Toplevel;. I need to keep this top level on top of my main window. This to prevent the "disappearing" of the dialog behind the main window. Until now I solved this problem with my $lifter = $dialog->repeat(100,sub{ $dialog->raise });. The problem is: if I have a drop-down menu in my dialog, the drop-down can not be selected any more, as the "rise" of the dialog window will cover it.

Do you know any other alternatives to achieve the same?

Replies are listed 'Best First'.
Re: Tk keep Toplevelwindow on top of its Mainwindow
by Corion (Patriarch) on Jun 26, 2018 at 12:53 UTC

    If you have a (modal) dialog window, maybe Tk::Wm::Popup is what you want instead?

Re: Tk keep Toplevelwindow on top of its Mainwindow
by zentara (Cardinal) on Jun 26, 2018 at 17:09 UTC
    You can always use the all-powerful overrideredirect(1). It's only drawback is your on-top window will be on top on every virtual desktop. The following script uses just about every trick. :-) It shouldn't leak memory with constant use.
    #!/usr/bin/perl use Tk; my $mw= MainWindow->new(); ################################################################## my $dialogdel = $mw->Toplevel(-bg=>'steelblue'); #my $dialogdel = MainWindow->new(-bg=>'steelblue'); $dialogdel->overrideredirect(1); $dialogdel->geometry('200x100+600+100'); $dialogdel->configure(-cursor => 'top_left_arrow'); $dialogdel->Label(-text=>"Ready to delete $key_sel", -bg=>'pink', -fg=>'black', -width=>20)->pack(-side=>'top',-fill=>'x'); my $dlabel = $dialogdel->Label(-text=>"Confirm delete $key_sel?", -bg=>'yellow', )->pack(-side=>'top'); $dialogdel->Button( -text => 'Delete', -bg=>'yellow', -activebackground=>'orange', -command => sub{print chr(07) })->pack; $dialogdel->Button( -text => 'Cancel', -bg=>'red', -activebackground=>'plum', -command => sub{$dialogdel->grabRelease; $dialogdel->withdraw; } )->pack(-side=>'right',-anchor=>'e'); $dialogdel->withdraw; ###################################################################### +#3 $mw->Button( -text => 'Delete', -bg=>'yellow', -activebackground=>'orange', -command => \&delete_key)->pack; MainLoop; sub delete_key{ $dialogdel->deiconify; $dialogdel->focus; $dialogdel->grab; }

    I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Tk keep Toplevelwindow on top of its Mainwindow (Tk::DialogBox)
by Anonymous Monk on Jun 26, 2018 at 13:13 UTC
Re: Tk keep Toplevelwindow on top of its Mainwindow
by Anonymous Monk on Jun 26, 2018 at 20:42 UTC

    you can use the following

    my $x = (($mw->x)+200); my $y = (($mw->y))+200; $dialog->geometry("+$x+$y"); if ($dialog->parent->toplevel->viewable){$dialog->transient($dialo +g->parent);}
Re: Tk keep Toplevelwindow on top of its Mainwindow
by Anonymous Monk on Jun 26, 2018 at 19:51 UTC

    Thank you for the suggestions. "DialogBox" is what I was looking for, but it has some limitations, such as "There is no control over the appearance of the Buttons in the bottom Frame nor is there any way to control the placement of the two Frames with respect to each other." which make it a no way for my project.

      but it has some limitations, "there is no control...", which make it a no way for my project

      Its only 153 lines long, Copy/paste the parts you need.