Simple ok/cancel routine
[email protected] (Philip Brady) Tue, 14 Jun 2016 17:29:41 +0000
| Newsgroups | perl.tcltk |
|---|---|
| Message-ID | <[email protected]> |
I'm writing a perl script using Tk and have had some success but I wish to have a very simple subroutine to ask the user a question and get a response 'ok' or 'cancel'.
My routine follows but it doesn't quite work as expected.
It's fine if I mouse click on 'ok' or simply press the return key - it correctly returns 'ok'.
If I clink 'cancel' it correctly returns 'cancel'.
Unfortunately, if I tab to 'cancel' then press return it returns 'ok' rather than the desired 'cancel'.
I'd appreciate any advice on fixing this.
regards
Phil
The code is:
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::Dialog;
use Tk::DialogBox;
my $main=MainWindow->new();
my $X=CheckOk('Some old question');
print "Response was $X\n";
exit 0;
sub CheckOk{
(my $question)=@_;
my $box=$main->DialogBox(
-buttons => ['ok','cancel'],
-default_button => "ok");
$box-> add("Label",
-text => "$question ")->pack;
$box -> Show();
}