Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Tk multiple monitor problem

by JohnRS (Scribe)
on Mar 09, 2012 at 18:31 UTC ( [id://958775]=perlquestion: print w/replies, xml ) Need Help??

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

Hello. I'm writing a GUI project using Strawberry Perl 5.12.3 and pTk 804.03. It is designed to run on Windows. I'm having a problem with DialogBox not positioning correctly in a multiple monitor environment. Everything I position with "show", "place", or "pack" works fine. But when I display a DialogBox on the left monitor it appears on the main monitor instead. To be more specific, it seems that "Show" doesn't like negative horizontal coordinates, replacing them with 0 instead. I've searched but have not found this problem mentioned elsewhere, except once back in 2002. So I'm thinking that there must be something I'm missing or others would have mentioned it since. Thanks for any help!

use strict; use warnings; use 5.012; use Tk; use Tk::DialogBox; my $mw = MainWindow->new; $mw->geometry('200x200+-300+300'); # Note the -300 horiz coord $mw->DialogBox(-buttons => [ 'OK' ]) ->Show(-popover => $mw); MainLoop;

Replies are listed 'Best First'.
Re: Tk multiple monitor problem
by Anonymous Monk on Mar 10, 2012 at 03:26 UTC

      Yes, from what I gather, the problem with Show is that the check to make sure that it places popups in viewable area fails because the test doesn't realize that there is a left monitor. This is somewhat odd considering that you can use the geometry command to put the main window there.

      Indeed, I have come up with a work around. It's tacky, but it works. Rather than fight Show's limitation, I use it as is, letting it place the popup incorrectly. Then I use a geometry command to move the popup to where it should be. Since your code stops running after the Show, I came up with the following way to accomplish this. Immediately prior to the Show I added the following.

      $mw->after(2, \&Popup_Position_Fix, $popup, $popover);

      The Popup_Position_Fix routine does some calculating then executes a geometry command on the popup. As I said, tacky, but it works. :)

        As long as it works, tacky is beautiful :) but grepping through the source, -popover should have worked, go figure

        Tk/DialogBox.pm

        Tk/Wm.pm

Re: Tk multiple monitor problem
by Khen1950fx (Canon) on Mar 09, 2012 at 22:39 UTC
    Try setting the screen option. On my system, the default would be :0.
    #!/usr/bin/perl use strict; use warnings; use 5.012; use Tk; use Tk::DialogBox; my $mw = MainWindow->new(-screen => $ARGV[0] || $ENV{'DISPLAY'}); $mw->geometry('200x200+-300+300'); $mw->DialogBox(-buttons => [ 'OK' ]) ->Show(-popover => $mw); MainLoop;

      I'm afraid that adding the parameters to "new" doesn't make any difference when I try it. The screen shows up on the left monitor, but the DialogBox shows up on the main monitor.

        Hmmm...Maybe Show needs to be handled differently. I tried this, but I used a different geometry.
        #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::widgets qw/DialogBox/; require Tk::LabEntry; my $uname = 'Anonymous'; my $pw = 'Anonymous'; my $mw = MainWindow->new( -screen => $ARGV[0] || $ENV{'DISPLAY'}, -bg => 'black', ); $mw->withdraw; my $box = $mw->title('Test'); $box = $mw->geometry('-1+1'); $box = $mw->DialogBox( -title => 'Login', -buttons => [ 'OK', 'Quit' ], -fg => 'red', -default_button => 'OK', ); $box->add( 'LabEntry', -textvariable => \$uname, -width => 20, -bg => 'black', -fg => 'green', -label => 'Username', -labelPack => [ -side => 'left' ] )->pack; $box->add( 'LabEntry', -textvariable => \$pw, -bg => 'black', -fg => 'green', -width => 20, -label => 'Password', -show => '*', -labelPack => [ -side => 'left' ] )->pack; $box->Show( -popover => $mw ); MainLoop;
        Updated; Added $mw->withdraw
Re: Tk multiple monitor problem
by Garden Dwarf (Beadle) on Dec 03, 2018 at 11:15 UTC

    Hello,

    This post is quite old and I do not find any other debate about this problem. I have the same issue now, and wonder if things have been fixed since then...

    My application is compiled with Par::Packer. It always start on the main display (physically on the right), even if my executable is opened from the second display (physically on the left). I didn't find a way to get the "active" display, so at start I am not able to change the window geometry because I don't know where to locate it (I even thought about the mouse coordinates, but I am not sure it will be reliable if the application is started with keyboard keys and not the mouse).

    My GUI has also dialogs windows and dropdown fields and are always displayed on the main monitor, even if the main window is on the second display. In that case I could apply the trick indicated above, but it is quite annoying as it happen for all kind of popup/dropdown.

    If someone has an idea, it will be much appreciated. Thanks in advance!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found