I don't know whether it's possible to create custom events with any event structure you'd like to define, but I fear it's not.
I'm not sure whether an event can be cancelled, but you can definitely not schedule the following one, and do nothing in the current one.
#! /usr/bin/perl use strict; use warnings; use Time::HiRes qw{ usleep }; use Tk; my $mw = 'MainWindow'->new(-title => 'Event demo'); $mw->bind('<<RowDone>>' => \&next_row); my $drawarea = $mw->Frame->pack(-side => 'top', -fill => 'both'); my $p = $mw->Photo(-width => 500, -height => 500); my $canvas = $drawarea->Canvas( -relief => 'ridge', -width => 500, -height => 500, -borderwidth => 4 )->pack; $canvas->createImage(0, 0, -anchor => 'nw', image => $p); $mw->Button(-text => 'Plot', -command => \&init) ->pack(-side => 'left'); $mw->Button(-text => 'Stop', -command => \&stop) ->pack(-side => 'left'); $mw->Button(-text => 'Quit', -command => sub { Tk::exit() }) ->pack(-side => 'left'); MainLoop(); { my ($y, $done); sub init { undef $done; $y = 0 if ! defined $y || $y == 500; $mw->eventGenerate('<<RowDone>>'); } sub next_row { return if $done; for my $x ( 0..499 ) { my $quality = long_computation($x, $y); $p->put(color($quality), '-to', $x, $y); } $canvas->update; if (++$y < 500) { $mw->eventGenerate('<<RowDone>>', -when => 'tail' ); } } sub stop { $done = 1 } } sub color { qw( red blue )[ rand 2 ] } sub long_computation { usleep(100) }
*Update*: return from next_row at the very beginning.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
In reply to Re: long computation in TK
by choroba
in thread long computation in TK
by BillKSmith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |