Hi, first off, you have a glaring error in your program flow. Once the line MainLoop is encountered, no further lines are processed until the MainLoop ( the Tk event loop system) is destroyed. So you never call eventGenerate until the Tk eventloop is gone, so it probably tries to run but throws an error.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = new MainWindow;
my $label = $mw -> Label(-text=>"Hello World") -> pack();
my $button = $mw -> Button(-text => "Quit");
$button->bind('<ButtonPress-1>' => \&myexit);
$button->pack;
$button->eventGenerate('<ButtonPress-1>');
$mw->repeat(1000 => \&doit);
sub doit {
$button->focus;
$button->eventGenerate('<ButtonPress-1>');
}
MainLoop;
sub myexit
{
print time."\n";
#exit;
}