Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Tk MainWindow from module Foo on to appear on top

by aplonis (Pilgrim)
on Oct 25, 2003 at 16:44 UTC ( [id://302077]=perlquestion: print w/replies, xml ) Need Help??

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

I have an app in several modules. Each module has its
own MainWindow. One such displays pop-up help in
a label widget (in its own MainWindow). I'd like
that one module's MainWindow to always appear on top,
above whatever other module's MainWindow
might be asked to display at almost the same time.

I tried calling it after the others. But some of
those display above it anyway. Can someone explain
this? How can I get around it without dedicating the
script to a given OS? It need not stay always on
top, only to appear on top when it does appear.

Thanks,
  • Comment on Tk MainWindow from module Foo on to appear on top

Replies are listed 'Best First'.
Re: Tk MainWindow from module Foo on to appear on top
by batkins (Chaplain) on Oct 25, 2003 at 17:41 UTC
    First of all, don't use multiple MainWindows. It's certainly possible, but parts of Tk aren't reliable when used with multiple MainWindows. Your best bet is to use Toplevels. You create one MainWindow and then create the other windows by making Toplevels from the MainWindow
    my $win = $mw->Toplevel(-title => 'ererree');
    If you don't want to have one and only one MainWindow (remember that closing a MainWindow exits your program), you can use only Toplevels and call $mw->withdraw immediately after creating the MainWindow. Your MainWindow will then be invisible and you'll only have Toplevels, which can be closed without requring the program to end.

    As far as your actual question, try $win->focus, where $win is the name of the window you want to bring to the front.


    The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. - Frank Zappa
      Yes, your suggestion works better yet. I will
      today fix my modules for Toplevels as apposed
      to MainWindows. And using $help_foo->focus
      works by itself without having to lower, raise the
      other window beforehand.

      Thanks again!

      This project to appear updated per todays meditative
      realization soon at Test Log GUI
Re: Tk MainWindow from module Foo on to appear on top
by graff (Chancellor) on Oct 25, 2003 at 17:14 UTC
    Have you tried using something like in the "help" module:
    $mainWin->raise;
    and something like this in each of the "non-help" modules:
    $mainWin->lower;
    I'm not totally sure that will work in all cases, but it's worth a try.

    If it was my app, I'd have the help window pop up only at the user's request. Put a "Help" button on one or more of the other windows. When all the "non-help" windows are up, and the user happens to push this button, the help window will certainly be on top -- but if someone uses this app more than a few times, they probably won't need or want to look at the help window every time they start it up.

      I just tried that. Thanks! After some few experiments
      it seems to work best if I do this way...

      $other_module::mw_other->lower
      $other_module::mw_other->raise
      $help_module::mw_help->raise

      I first lowered, then raised the other module's
      MainWindow before raising the help module's as I
      wanted the other module's MainWindow to be
      second-from-top, just under that of the help
      module.

      Thanks,

      PS -- The URL for this project (soon to be updated
      for todays meditative realization) is Test Log GUI
Re: Tk MainWindow from module Foo on to appear on top
by PERLscienceman (Curate) on Oct 27, 2003 at 22:41 UTC
    Here is another possibility:
    This is a module that I found on CPAN that and determined to be quite useful. I believe it may fit the sceanrio that you have described: Tk::StayOnTop. It's CPAN Description: Adds methods to the Tk::Toplevel base class so that a window can stay on top off all other windows.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 19:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found