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

Dear Monks, Greetings.

Below is the code, I want to get the $toplevel window, which displays the progressbar to display over the main window, and however it always hides behind the main window. Is there away that I can get it to display in front of the not behind the main window.

Thanks
#! c:/perl/bin/perl.exe -slw use strict; use warnings; use Tk; use Tk::ProgressBar; my $mw= MainWindow->new (-title=> 'Main Window'); $mw->geometry('900x700'); my $percent_done=0; my $count = 0; chomp (my @data=<DATA>); my $toplevel = $mw->Toplevel; my $Progress = $toplevel->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [0,'blue',100,'blue'], -variable => \$percent_done)->pack(-fill=> 'x'); $toplevel->focus; for (@data) { print STDOUT "$_\n"; $percent_done =$count/scalar(@data)*100; sleep(1); $count++; $toplevel->update; } $toplevel->destroy; MainLoop; __DATA__ winhost1 winhost2 winhost3 winhost4
Blackadder

Replies are listed 'Best First'.
Re: Getting Tk::Toplevel window to disply on top
by rinceWind (Monsignor) on Dec 23, 2004 at 15:37 UTC
    Look at the discussion on thread "Always on top" with Win32 and Tk - this is only a Windows solution. An alternative is to withdraw then deiconify the toplevel, which should work on all platforms.

    --
    I'm Not Just Another Perl Hacker

      Thanks Guys

      This statment from spikey_wan is interesting;

      "I can't believe no-one's mentioned Tk::StayOnTop. It does what it says on the tin. "

      I will give it ago.
      Blackadder
Re: Getting Tk::Toplevel window to disply on top
by maa (Pilgrim) on Dec 23, 2004 at 15:42 UTC

    If you declare/create your $toplevel widget that contains the Progress Bar before the MainWindow it will be in front for it's short life.

    HTH- Mark

      Can't do that!

      I am using strict, I have to declare $mw before $toplevel!

      I am not exactly sure how you mean!

        Sorry... what I mean is don't make it a child of $mw...

        my $toplevel=MainWindow->new(-title=>'Progress Bar'); my $mw=MainWindow->new(-title=>'Main Window');

        Hope that's clearer, I was just leaving work yesterday when i posted that.

Re: Getting Tk::Toplevel window to disply on top
by zentara (Cardinal) on Dec 23, 2004 at 17:58 UTC
    If worse comes to worse, you can always setup a timer, that runs for the duration of the ProgressBar, in the sub for the timer, just do $toplevel->raise. It will keep making the toplevel come to the top. You might also be able to do it in your ProgressBar loop. Or check out this:
    #!/usr/bin/perl #$top->deiconfiy; #$top->raise; use Tk; $mw = tkinit; $t = $mw->Toplevel; $t->withdraw; $t->Label(-text => "Testing...")->pack; $t->Button( -text => "Withdraw", -command => sub {$t->withdraw}, )->pack; $t ->overrideredirect(1); #to top on all virtual desktops $mw->Button( -text => 'Test', -command => sub { $_->deiconify, $_->raise for $t; }, )->pack; MainLoop;

    I'm not really a human, but I play one on earth. flash japh