Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How to adjust -tk program to the width of the screen?

by tamaguchi (Pilgrim)
on Oct 24, 2006 at 18:58 UTC ( [id://580372]=perlquestion: print w/replies, xml ) Need Help??

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

Suppose I have a fascinating tk-program like this..
#!/usr/bin/perl -w use Tk; use strict; my $mw = MainWindow->new; my $c = $mw->Canvas( -width => 500, -height => 500, -background =>'blue', -scrollregion =>[0, 0, 100, 100]); $c->pack; $c->createRectangle(100, 100, 150, 150, -fill => 'yellow'); MainLoop;
..a yellow rectangle on a canvas. Is it possible to modify the program so that the frame automaticaly adjusts to the width of the screen when the program is run? Thank you for any help.

Replies are listed 'Best First'.
Re: How to adjust -tk program to the width of the screen?
by liverpole (Monsignor) on Oct 24, 2006 at 19:13 UTC
    Hi tamaguchi,

    If by width of the screen you mean just the window itself, that's easy:

    $c->pack(-expand => 1, -fill => 'both');

    But if you mean, as I think you do, the width of the monitor screen, try using the methods vrootheight and vrootwidth as well:

    #!/usr/bin/perl -w use Tk; use strict; my $mw = MainWindow->new; my $vh = $mw->vrootheight; my $vw = $mw->vrootwidth; # Note that the 'virtual window' height and width are $vh and $vw # respectively, so we use those dimensions for our Canvas height # and width, and let the Canvas expand and fill in both x and y # directions. # my $c = $mw->Canvas( -width => $vw, -height => $vh, -background =>'blue', -scrollregion =>[0, 0, 100, 100]); $c->pack(-expand => 1, -fill => 'both'); $c->createRectangle(100, 100, 150, 150, -fill => 'yellow'); MainLoop;

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: How to adjust -tk program to the width of the screen?
by zentara (Archbishop) on Oct 24, 2006 at 20:10 UTC
    Here's another anti-social snippet for you to look at. :-)
    #!/usr/bin/perl use warnings; use strict; use Tk; my $main = MainWindow->new(-title => "Resize Test"); $main->geometry("600x400+100+100"); $main->Button( -text => "Exit Program", -command => sub { exit } )->pack(); my $button = $main->Button( -text => "Go To Fullscreen", -command => \&resizer, )->pack(); MainLoop; sub resizer{ if ( $button->cget(-text) =~ /Fullscreen/ ){ $main->geometry($main->screenwidth . 'x' . $main->screenheight . '+0+0'); $button->configure(-text=>"Go to Window"); }else{ $main->geometry("600x400+100+100"); $button->configure(-text=>"Go To Fullscreen"); } }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: How to adjust -tk program to the width of the screen?
by Fletch (Bishop) on Oct 24, 2006 at 19:51 UTC

    Ability to do this aside, keep in mind that grabbing the entire screen could be considered anti-social behavior by some. If I want your window to take up the entire available real estate I'll tell my window manager to make it so.

    (Of course there's exceptions, things like VNC clients that are representing the entire remote display in a special full screen mode; but those are few and far between.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-26 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found