Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Tk window to the front of all application windows

by crabbdean (Pilgrim)
on Apr 12, 2004 at 21:34 UTC ( #344537=perlquestion: print w/ replies, xml ) Need Help??
crabbdean has asked for the wisdom of the Perl Monks concerning the following question:

A program I wrote pops up with a Tk window as an error dialog. Works nicely although I've noticed it often doesn't bring itself to the VERY front of all my other applicaton windows. As an error dialog this isn't desirable. Below is the code for the error dialog which I call from main. The "withdraw/popup" methods centre it on the screen, which I want to keep. The "focus" method I thought would bring it to the front but no such luck. I've also tried "raise". Does anyone know how to force it to the front on a Win32 system? Thanks
sub dying { my ($error) = @_; if (!$error) { $error = "(none given)"; } my $text; $text .= "\n\nTARsync Error:\n\nFailed during:\n$message\n\nReason +:\n$error"; if ($poperr) { my $box = new MainWindow(-title => "ZIPsync failed!", -bg => 'yellow', -bd => 4, -relief => 'ridge'); $box->overrideredirect(1); my $label = $box->Label( -textvariable=> \$text, -bg=> 'yellow', )->pack(-fill=>'both', -padx => 40, ); Win32::Sound::Play('SystemExclamation'); my $ok = $box->Button(-text => "OK", -command => [sub{$box->destroy; exit; } ] )->pack(-padx => 20, -pady => 20 ); $box->withdraw; $box->Popup; $box->focus; MainLoop; }

Dean
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers

Comment on Tk window to the front of all application windows
Download Code
Re: Tk window to the front of all application windows
by saintmike (Vicar) on Apr 12, 2004 at 21:46 UTC
    Interesting, this seems to be a shortcoming on perlTk for Win32 systems only -- it works fine on Linux.

    Also, the Tk::focus manual page mentions focusForce() which claims to force the focus on the application if it doesn't have it, but that doesn't work either on Win32.

Re: Tk window to the front of all application windows
by rinceWind (Monsignor) on Apr 12, 2004 at 23:34 UTC
Re: Tk window to the front of all application windows
by eserte (Deacon) on Apr 13, 2004 at 09:23 UTC
    With Tk804.027 you could try the new $mw->attributes(-topmost => 1) method call.
Re: Tk window to the front of all application windows
by crabbdean (Pilgrim) on Apr 13, 2004 at 20:02 UTC
    A SOLUTION: I awoke during the night recalling a method I'd seen in the Win32Util module about "always keep ontop". Its a bruteforce way of forcing your Tk Window to the front and *keeping it there* even if you maximise other windows. See the amended code below. (Note: setting the optional flag to 1 forces it ontop, setting it to 0 disables it.

    The mind of a programmer never sleeps! :-)
    ## Insert these into main use Win32::Sound; use Win32Util; ## subroutine for dying sub dying { my ($error) = @_; if (!$error) { $error = "(none given)"; } my $text; $text .= "\n\nTARsync Error:\n\nFailed during:\n$message\n\nReason +:\n$error"; if ($poperr) { my $box = new MainWindow(-title => "TARsync failed!", -bg => 'yellow', -bd => 4, -relief => 'ridge'); $box->overrideredirect(1); my $label = $box->Label( -textvariable=> \$text, -bg=> 'yellow', )->pack(-fill=>'both', -padx => 40, ); Win32::Sound::Play('SystemExclamation'); my $ok = $box->Button(-text => "OK", -command => [ sub{$box->destroy; exit; } ] )->pack(-padx => 20, -pady => 20 ); $box->withdraw; $box->Popup; Win32Util::keep_on_top($box, 1); MainLoop; } }

    Dean
    The Funkster of Mirth
    Programming these days takes more than a lone avenger with a compiler. - sam
    RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-09-21 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls