Reputation: 10154
Is there a way to make a Perl/Tk window's close ('X') button disabled? I know how to ignore clicking it using the technique described here, but I would much rather have it disabled.
I'm using Perl/Tk on Windows.
Thanks,
splintor
Upvotes: 2
Views: 3447
Reputation: 163
If you don't manage to really disable the close button (I mean to grey it out or even remove it from the window decoration), it might be the most intuitive thing to iconify your window instead of closing it. This is what I did.
$window->protocol('WM_DELETE_WINDOW', sub { $window->iconify(); } );
Upvotes: 0
Reputation: 1339
According to the Perl Monks, it looks like the following works on Windows:
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $window = new MainWindow;
$window ->title("Close test");
$window ->geometry("400x250");
#prevents window from closing
$window->protocol('WM_DELETE_WINDOW' => sub {
print "Do stuff before exiting\n";
exit;
});
MainLoop;
In the above code, you are intercepting the signal sent when the user presses 'X' and can then write your own subroutine to execute when the button is pressed.
If you want to disable the close icon, set sub
to empty (effectively telling it to "do nothing when pressed"): 'WM_DELETE_WINDOW' => sub {}
Upvotes: 0
Reputation: 21
I have an app that I wrote, i was wondering about the same thing, and i don't disableit, but i have a call back to a subroutine, that simply does return;
$Mw->protocol('WM_DELETE_WINDOW',sub{return;});
Upvotes: 2
Reputation: 8054
If you are in a Unix environment you are out of luck. The "close" button is managed by the Window Manager
of the desktop which is a completely different process that you have no control on.
Even if by a hack you disable the "close" button the user can always bring it back if the window manager permits this. The enlightenment window manager for example can enable/disable all window buttons on demand.
The technique you give in the link is doing exactly this. It does not remove
the "close" button. It just gives a hint to the window manager (WM_DELETE_WINDOW
).
It is up to the window manager if this hint will be honoured or not.
See also the icccm and NetWM pages.
What you want might be possible on Windows, but my experience with this OS is limited so perhaps another poster will know this.
Upvotes: 2