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

Hi there monks

The following issue disturbs me: I'm using overrideredirect to remove decorations and as a result the widget is always on top. This is usually fine, but sometimes I want to have a popup on top of the MW, but overrideredirect seems to always win. Is there anyway to make a window on top of an overrideredirect window? I've extended a famous example to emphasize the issue

#!/usr/bin/perl -w use strict; use Tk; my $mw = tkinit; my $notification = $mw->Toplevel(); $notification->geometry('+400+400'); $notification->overrideredirect(1); # Remove window decorations $notification->withdraw; # Hide display window $notification->Label( -text => 'Your message displayed here.', -foreground => 'white', -background => 'black', -height => 5 )->pack; $notification->Button( -text => 'Press Me', -command => sub {my $msg = $mw->messageBox(-icon => 'error', -message => "No tests selected", -title => 'Error', -type => 'Ok', -default => 'Ok'); } )->pack; $mw->Button( -text => 'Display Notification Window', -command => \&display_note )->pack; MainLoop; sub display_note { $notification->deiconify; $notification->raise; # this is where you setup a condition to withdraw it $notification->after( 5000, \&hide_note ); } sub hide_note { $notification->withdraw; }

Replies are listed 'Best First'.
Re: Prevent overidedirect from being always on top (1+1 != 2 )
by Anonymous Monk on Jan 27, 2015 at 09:22 UTC

    So you're saying that your messageBox doesn't show on top of the $notification?

    It does for me, win32, Tk 804.030

      Well on KDE (Linux) - it doesn't :(
Re: Prevent overidedirect from being always on top
by Anonymous Monk on Jan 27, 2015 at 21:22 UTC
    Here is something you might work on; you can turn off the overrideredirect flag. Possibly you could work out a system to remove the flag when you need to place something on top, then restore the flag when done.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; $mw->geometry("200x300+200+200"); $mw->overrideredirect(1); # set the override-redirect flag $mw->packPropagate(0); # prevent the window being resized # for this demo $mw->Button( -text => 'Quit', -command => sub { Tk::exit(0) }, )->pack( -side => 'bottom', ); # after a delay: # withdraw # clear the override-redirect flag # re-map the window $mw->after( 4000, sub { $mw->withdraw; $mw->overrideredirect(0); $mw->deiconify; $mw->raise; } ); # NB: # "Mastering Perl/Tk" mentions that clearing # the override-redirect flag will not cause # the window manager to supply decorations. # This is true, but at least on KDE, clearing # the flag, then unmapping and mapping the # window puts decorations in place. # # Your mileage may vary. MainLoop;

      That is clever, but is it needed?

      as far as I can tell, it isn't needed, as the messagebox pops up on top of the notification no matter what happens

      #!/usr/bin/perl -- use strict; use warnings; use Tk; Main( @ARGV ); exit( 0 ); sub Main { my $mw = tkinit( ); $mw->geometry('+300+400'); my $notification = $mw->Toplevel( ); $notification->geometry('+400+400'); $notification->overrideredirect(1); # Remove window decorations $notification->withdraw; # Hide display window $notification->Label( -text => 'keep clicking toggle ', -foreground => 'white', -background => 'black', -height => 5 )->pack; $notification->Button( -text => 'Press Me', #~ -command => [ \&important_message, $notification ], ## not +needed -command => \&important_message, )->pack; $mw->Button( -text => 'Display Notification Window', -command => [ 'deiconify', $notification ], )->pack->focus; $mw->Button( -text => 'toggle topmost notification ', -command => [ \&toggle_topmost , $notification ], )->pack; $mw->Button( -text => 'hide notification ', -command => [ 'withdraw', $notification ], )->pack; ## $mw->WidgetDump; ## debugging aid MainLoop; } sub important_message { #~ my( $n ) = @_; my( $n ) = $Tk::widget; #~ my $msg = $mw->messageBox( ## works to raise above $notificatio +n on win32, might not work on all platforms my $msg = $n->messageBox( -icon => 'error', -message => "No tests selected", -title => 'Error', -type => 'Ok', -default => 'Ok', ); } sub toggle_topmost { my( $n ) = @_; warn $n->attributes; $n->attributes(-topmost => ! $n->attributes(-topmost ) );; $n->parent->raise; $n->parent->focus; } __END__ __END__