Here's some complete example code below. Examples 1, 2, and 3, work. Example 4 does not. ???
Example 1.
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; $mw->Button(-text => "Paste", -command => \&DoPaste)->pack(); my $t = $mw->Text(-width => 30, -height => 5)->pack(); $t->focus; sub DoPaste { print "DoPaste\n"; $t->eventGenerate('<Control-v>'); } Tk->MainLoop;
Example 2
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; $mw->Button(-text => "Paste", -command => \&DoPaste)->pack(); my $t = $mw->Text(-width => 30, -height => 5)->pack(); $t->focus; sub DoPaste { print "DoPaste\n"; $mw->eventGenerate('<Control-v>'); } Tk->MainLoop;
Example 3 (the virtual event generated off of the widget)
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; $mw->Button(-text => "Paste", -command => \&DoPaste)->pack(); my $t = $mw->Text(-width => 30, -height => 5)->pack(); $t->focus; sub DoPaste { print "DoPaste\n"; $t->eventGenerate('<<Paste>>'); } Tk->MainLoop;
Example 4. Paste button doesn't work. The widget's virtual paste event is not being generated, it seems. If the virtual paste binding weren't tagged with the widget's class then I think it would work. But the real control-v event works regardless. How rude!
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; $mw->Button(-text => "Paste", -command => \&DoPaste)->pack(); my $t = $mw->Text(-width => 30, -height => 5)->pack(); $t->focus; sub DoPaste { print "DoPaste\n"; $mw->eventGenerate('<<Paste>>'); } Tk->MainLoop;
Can anybody explain why this works the way it does. Why generating a virtual event doesn't seem to work the same as generating a 'real' event? My initial impulse is to assume this is a bug, but I make that assumption a lot, and I've never turned out to be right. It's never a bug, I'm just always misunderstanding something. What am I misunderstanding?
In reply to virtual events and real events with eventGenerate seem to not work the same... by gleepglop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |