bringing a process to foreground.

R

rajendra

Hello All,
In one of script, I use a Perl TK to get the user login information. But by
the time, I get the TK window for login, if I change my focus to some other
process, the Perl TK window will be in background.
So I would like to know how to bring this Perl TK window to foreground.
 
Z

zentara

Hello All,
In one of script, I use a Perl TK to get the user login information. But by
the time, I get the TK window for login, if I change my focus to some other
process, the Perl TK window will be in background.
So I would like to know how to bring this Perl TK window to foreground.

You could use $mw->overrideredirect(1); to make the window
grab global focus and stay on top on all virtual desktops; but that
is often too harsh, and demands immediate attention.

What you probably could do, is use a timer to keep the
window on top. When you want to cancel the stay-on-top;
cancel the $repeater

#!/usr/bin/perl
use Tk;
use strict;
use warnings;

my $top = new MainWindow;
my $repeater;

keep_on_top($top);

#cancel after 10 seconds
$top->after(10000, sub{ $repeater->cancel });

MainLoop;

sub keep_on_top {
my $w = shift;
#raise every tenth second
$toprepeater = $w->repeat(100,
sub{ $w->raise });
}
__END__
 
C

Ch Lamprecht

rajendra said:
Hello All,
In one of script, I use a Perl TK to get the user login information. But by
the time, I get the TK window for login, if I change my focus to some other
process, the Perl TK window will be in background.
So I would like to know how to bring this Perl TK window to foreground.
Hi,

if you are on windows, you can use

$main_window->attributes(-topmost => 1);

That will work with MainWindow or Toplevel objects.

Christoph
 
A

aakash

Hello All,
When i tried to use the below command it gives me an error : "Can't call
method "attributes" on unblessed reference at ( folllowed by line no.)"

Aakash
 
C

Ch Lamprecht

aakash wrote:


When i tried to use the below(above) command it gives me an error : "Can't
call
method "attributes" on unblessed reference at ( folllowed by line no.)"

Hi aakash,
please post a short but complete example.
Please don' top-post.

Christoph
 
R

rajendra

Hello All,
Please find my small script.

use Tk;
$main=MainWindow->new;
$main->Button(-text => "Click",-command => \&disp)->pack(-side =>'left');
$text1=$main->Text(-width => 40 ,-height => 2)->pack;
$text1->bind('<Enter>',\&disp);

MainLoop;

sub disp
{
$text1->insert('end',"Hello");
}

What should I add for this script to bring the window that gets generated by
this script to foreground even if I change my focus?..
 
C

Ch Lamprecht

rajendra said:
Hello All,
Please find my small script.

use Tk;
$main=MainWindow->new;
$main->Button(-text => "Click",-command => \&disp)->pack(-side =>'left');
$text1=$main->Text(-width => 40 ,-height => 2)->pack;
$text1->bind('<Enter>',\&disp);

$main->after(500,sub{$main->attributes(-topmost=> 1)});
# this works on windows
MainLoop;

sub disp
{
$text1->insert('end',"Hello");
}

What should I add for this script to bring the window that gets generated by
this script to foreground even if I change my focus?..

Again: It's easier to follow the discussion if you don't top-post.

Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top