Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Perl Tk Active Window

by NeonFlash (Novice)
on Aug 18, 2012 at 05:36 UTC ( #988155=perlquestion: print w/replies, xml ) Need Help??
NeonFlash has asked for the wisdom of the Perl Monks concerning the following question:

I have created a scheduled task on Windows 7 which runs a Batch File at a specified interval.

This batch file in turn invokes a Perl Script. Inside the Perl Script, based on the result, I use Perl Tk to display a Popup Message which gives an Alert.

Now, while I am doing some other task on my machine, like Browsing Internet, the Browser Window will be the active window for instance. In between, the scheduled task runs and the popup Window is not displayed, instead it is minimized and displayed on the Task Bar.

Please note that I am using, htstart.exe from ntwind to avoid displaying the Console Window when the Scheduled task runs (otherwise, taskeng.exe shows up everytime the scheduled task runs).

In order to make my Perl Tk window as the active window, I am creating the window as shown below:

$mw = MainWindow->new(-background => 'blue'); $mw->focus(-force); $mw->geometry("200x200"); $mw->title("Message"); $mw->Label(-text => 'A Message', -background => 'white', -font => 'big +')->pack(); $mw->Button(-text => "Close", -command =>sub{exit})->pack(); MainLoop;

I have set the focus option so that this window becomes active.

Now, when the scheduled task runs, the only difference I observed after setting the focus option is that, the Tk Window appears in the Taskbar and it keeps blinking (probably because it is set as the active window now).

How do I make sure, that when it is displayed, it appears in the foreground and does not get minimized to the Task Bar?


Replies are listed 'Best First'.
Re: Perl Tk Active Window
by zentara (Archbishop) on Aug 18, 2012 at 09:19 UTC
    Using a timer used to work, but I just tested it, and it dosn't raise the window, it just flashes its icon. You could try $mw->overrideredirect(1); but it will show up on all virtual desktops. As an alternative, Gtk2 has a more flexible override which allows the override on each virtual desktop of your system.
    #!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $window = Gtk2::Window->new(); #$window->set_decorated(0); #Gtk2::Window::set_decorated($window, 0); #print $window->get_decorated(),"\n"; #$window->stick; #$window->unstick; #Gtk2::Window::set_keep_above($window, 1); $window->set_keep_above(1); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(300,200); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $window->add( $button); $button->signal_connect( clicked => \&delete_event ); $window->set_position('center'); $window->show_all(); $window->stick; Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Perl Tk Active Window
by rpnoble419 (Pilgrim) on Aug 18, 2012 at 18:39 UTC
    Try the Win32::MsgBox out of the Win32 module. This pops up a system message box without the TK overhead. The code example below will execute the popup after the script runs
    use Win32; use strict; END{ Win32::MsgBox("I'm Done.", MB_ICONINFORMATION); }
Re: Perl Tk Active Window
by Anonymous Monk on Aug 18, 2012 at 06:27 UTC

    How do I make sure, that when it is displayed, it appears in the foreground and does not get minimized to the Task Bar?

    Try withdraw , raise, deiconify

      I tried these methods as well and they did not work. However, I came across this->

      Trying it now and hope it works :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://988155]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-04-20 09:52 GMT
Find Nodes?
    Voting Booth?