in reply to Perl Tk variable update question
Since you did not give a running code example, your code fragments are not clear if you are nesting subroutines or not.
ensure that $receiptno is updated and data is written to text file only if a new set of data is entered by the user?
There are probably more elegant ways of doing it, but one way is to keep a list of all the $receiptnos that get printed out, and check that list before any new print.
If the idea is to stop multiple simultaneous prints, set the button state to disabled at the start of the print routine, and set back to normal at end of the print sub.
This example shows the idea
#!/usr/bin/perl use warnings; use strict; use Tk; my $FILTER_IS_ON = 0; my $top = new MainWindow(); my $c1 = $top->Button(-text=>$FILTER_IS_ON ? 'turn off' : 'turn on', -command => \&turn)->pack(); my $c2 = $top->Button(-text=> 'Go', -state => 'disabled', -command => sub { print "ook!\n" })->pack(); MainLoop(); sub turn { $FILTER_IS_ON = $FILTER_IS_ON ? 0 : 1; $c1->configure(-text=> $FILTER_IS_ON ? 'turn off' : 'turn on'); $c2->configure(-state=> $FILTER_IS_ON ? 'normal' : 'disabled'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |