Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Urgent query : PERL/Tk

by Anonymous Monk
on Nov 30, 2005 at 06:12 UTC ( #512859=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi friends, In perl/tk how can I disable the minimize and maximize properties in the top level window? I just want 'close' sign on the window. I mean to say this window:
my $main=new MainWindow;
Plz respond ASAP. Thanks in advance.

Comment on Urgent query : PERL/Tk
Download Code
Re: Urgent query : PERL/Tk
by sk (Curate) on Nov 30, 2005 at 07:09 UTC
Removing maximize/minimize in Perl/Tk (Urgent query: PERL/Tk)
by rcseege (Pilgrim) on Nov 30, 2005 at 07:53 UTC

    Well, this isn't exactly what you're looking for, but it's close. It's somewhat similar to one of the postings in the suggested thread, but simpler.

    use Tk; my $mw = MainWindow->new; my $toplevel = $mw->Toplevel; $toplevel->transient($mw); MainLoop;

    You can also use overrideredirect as suggested in the thread but you will lose all window decorations, and will be forced to do something like this to move the window around:

    use strict; use Tk; my $mw = MainWindow->new; $mw->overrideredirect(1); my $frame = $mw->Frame-> pack(-padx => 20, -pady => 20); $frame->Button( -text => 'Exit', -command => sub { Tk::exit } )->pack; my ($lastX, $lastY); $mw->bind('<Button1-Motion>', [\&MoveWindow, Ev('X'), Ev('Y'), \$lastX, \$lastY]); $mw->bind('<ButtonRelease-1>', [\&ClearCoords, \$lastX, \$lastY]); MainLoop; sub ClearCoords { my ($cw, $xSR, $ySR) = @_; undef($$xSR); undef($$ySR); } sub MoveWindow { my ($mw, $rootX, $rootY, $xSR, $ySR) = @_; if (!defined($$xSR) && !defined($$ySR)) { $$xSR = $rootX; $$ySR = $rootY; } else { my $xDiff = $rootX - $$xSR; my $yDiff = $rootY - $$ySR; my $x = $mw->x + $xDiff; my $y = $mw->y + $yDiff; $x = "+".$x if $x >= 0; $y = "+".$y if $y >= 0; $mw->geometry(sprintf("%dx%d%s%s", $mw->width, $mw->height, $x, $y )); $$xSR = $rootX; $$ySR = $rootY; } }

    If you are working in a Win32 environment only, you might consider checking out Win32::GUI. What you're looking to do is fairly easy using it.

    Rob
Removing maximize/minimize in Perl/Tk (Urgent query: PERL/Tk)
by rcseege (Pilgrim) on Nov 30, 2005 at 15:50 UTC

    Here's another approach using Win32::GUI that I haven't seen posted. It's a variation of something I've done in other programming languages, but it seems to work well enough on my desktop running XP. The downside is that it pretty much throws portability out the window.

    use Tk; use Win32::GUI; my $mw = MainWindow->new; $mw->title("Hello"); $mw->update; my ($winH) = Win32::GUI::FindWindow("", "Hello"); my $style = Win32::GUI::GetWindowLong($winH, -16); $style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX); Win32::GUI::SetWindowLong($winH, -16, $style); Win32::GUI::DrawMenuBar($winH); MainLoop;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-09-16 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (158 votes), past polls