As part of a validatecommand for an entry widget I want to update a label widget as well as change the background color of the entry itself. I find that if I call update() on either the entry or label in the validating sub it will randomly stop working. The debug print statement in the sub stops, the background stops changing, the label stops getting updated, it sure seems to not be either being called or something is wedged. Everything else appears to work fine. I've extracted an example below. If I comment out the update() in inline_validate_section() it seems fine and works as desired, but the examples I followed (some from perlmonks) include update(), I'm curious to understand whats going on.
The code below will take a few to a few dozen inputs before no longer validating..On older 586 class hardware this was written to run on it seems to fail very quickly, on my 2016 MBP it takes some rapid inputs, so it seems like maybe a timing thing.
use Tk;
%mults = (
A => "a",
B => "b",
);
sub inline_validate_section {
my $entry = uc(shift);
print "$entry\n";
if(defined($mults{$entry}) || !$entry){
$Inputs{Section}->configure(-background => lightgrey);
$Telltale{Section}->configure(-text => "$mults{$entry}");
$Telltale{Section}->update();
} else {
$Inputs{Section}->configure(-background => red);
$Telltale{Section}->configure(-text => "nope");
$Telltale{Section}->update();
}
return 1;
}
my $main = MainWindow->new();
$main->geometry('400x100');
# two frames and adjuster
my $main_frame = $main->Frame; # right
# pack frames
$main_frame->pack(qw/-side right -fill both -expand l/);
$vn = "Section";
$main_frame->Label(-text => $vn, -width => 15)->pack(qw/-side left/)
+;
$Inputs{$vn} = $main_frame->Entry(-validate => 'key',
-validatecommand => [\&inline_validate_section],
-textvariable => \$$vn)->pack(qw/-side left -padx
+10 -pady 5 -fill x/);
$Telltale{$vn} = $main_frame->Label(-text => "nope", -width => 25)->
+pack(qw/-side left/);
MainLoop();
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.