Hello Monks,
I'm not sure what exactly is causing the problem. There aren't any past threads I could see on this topic which mention this issue either. Anyway, below is a small program which consistently demonstrates this problem.
This program when run brings up a window with 'OK' button which when clicked brings a dialog box. This dialog box has an Entry widget which displays a text: HAPPY 07-OCT-2014 and also the default buttons (OK and Cancel)
Once the dialog box pops up, here are the steps to re-produce this problem
- highlight a portion of the text displayed in the entry widget (i.e. HAPPY 07-OCT-2014 ) by draging the mouse
- Press 'Backspace' key on the keyboard so that the highlighted portion of the text is deleted.
- Now press 'OK' any number of times, the dialog box stays there and dialog_callback is not called.
(NOTE: after pressing the backspace but before clicking OK button, make sure not to switch the focus from this dialog box to other windows or applications)
- Only when you move the mouse pointer even little outside the OK button and then you bring it back into OK button, does make the OK button work as desired.
- The same sequence can be tried with 'Cancel' button as well.
use warnings;
use strict;
use Tk;
my $mw = MainWindow->new;
$mw->Button (-text=>'OK', -command=>\&popup_dialog)->pack;
MainLoop;
sub popup_dialog {
my $dialog = $mw->DialogBox(
-title=>'A Tk DIALOG BOX',
-buttons=>['OK', 'Cancel'],
-default_button=>'OK',
-cancel_button=>'Cancel',
-command=>\&dialog_callback);
my $entry = $dialog->Entry(
-text=>'HAPPY 07-OCT-2014',
-borderwidth=>3,
-takefocus=>1,
-font=>'{Architects Daughter} -15 bold')
->grid(-padx=>"1m", -pady=>"2m", -sticky=>'w');
#workaround code -- begin
$entry->bind('<Key-BackSpace>'=>sub{
print "inside BackSpace callback\n";
$_[0]->icursor(0);
$_[0]->eventGenerate('<ButtonPress-1>');
$_[0]->eventGenerate('<ButtonRelease-1>');
$_[0]->eventGenerate('<ButtonPress-1>');
$_[0]->eventGenerate('<ButtonRelease-1>');
$_[0]->selectionClear;
$_[0]->focus;});
#workaround code -- end
$dialog->Show;
}
sub dialog_callback {
print "inside dialog callback\n";
}
Please note that there is a backspace binding for the entry widget. This was done only to workaround another problem. i.e. if the binding was not there, then it causes a frequent but sporadic problem. Here are the steps to re-produce that problem
- remove the backspace binding and run the program.
- Now highlight a portion of the text other than the date. ie. (do not highlight 07-OCT-2014 but only the text HAPPY and the blank space after it) by dragging the mouse from right to left and the hit backspace key. (this should be done failrly quickly i.e. dragging the mouse right to left to highlight the text and hitting backspace)
- Now you would see that for some reason the zero in remaining text after deletion (i.e. 0 in 07-OCT-2014) is highlighted and clicking the OK button doesn't work.
But applying this work around for this frequent-but-sporadic problem brought in the consistent problem stated above.
Couple of weeks ago I filed query on 'Table Matrix row selection question' A TableMatrix row selection question and the monks indeed came to my help with detailed answers. I sincerely hope there would be few monks to help this time as well.
Lastly here are the system details I'm using:
System Configuration:
I'm using Windows XP, Strawberry Perl v5.16.3,
Tk::DialogBox.pm v4.016, Tk::Entry.pm v4.018
(from strawberry/perl/site/lib/Tk)
Many Thanks