Leser: 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/local/bin/perl use strict; use warnings; use Tk; use Tk::TextUndo; my $mw=MainWindow->new(-title=>'CTRL-S Test'); my $text = $mw->Scrolled('TextUndo', -scrollbars=>'osoe', -width=>40, -height=>15)->pack; my $closebutton = $mw->Button(-text=>'Close', -command=>sub {$mw->destroy;})->pack(-fill=>'x'); $text->bind('<Control-KeyPress-r>',sub{$text->delete('insert - 1 chars'); print "CTRL-R gedrückt\n";}); $text->bind('<KeyPress>', [\&text_validate,Ev('A')]); MainLoop(); sub text_validate { my ($text,$A) = @_; if ($A eq chr(19)) { # CTRL-S gedrückt #$text->break; print "Gotcha\n"; $text->break; } else { print "weiter\n"; } }
QuoteThe order of the elements in tagList determines the order in which binding scripts are executed in response to events.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/local/bin/perl use strict; use warnings; use Tk; use Tk::TextUndo; my $mw=MainWindow->new(-title=>'CTRL-S Test'); # Scrolled weggemacht und schon gehts my $text = $mw->TextUndo(-width=>40, -height=>15)->pack; my $closebutton = $mw->Button(-text=>'Close', -command=>sub {$mw->destroy;})->pack(-fill=>'x'); $text->focus(); $text->bind('myValidate', '<KeyPress>', [\&text_validate,Ev('A')]); $text->bindtags(['myValidate',$text->bindtags]); MainLoop(); sub text_validate { my ($text,$A) = @_; if ($A eq chr(19)) { #CTRL-s gedrückt print "CTRL-s gedrueckt. speichern.\n"; save_me(); $text->break; } elsif ($A eq chr(6)) { print "CTRL-f gedrueckt. Zeige Find Popup.\n"; $text->FindPopUp; $text->break; } else { print "weiter\n"; } } sub save_me { print "saved\n"; }
2010-03-20T16:05:06 KalleWarum ich auch noch 'Scrolled' rausnehmen musste, weiss ich allerdings noch nicht.
my $text = $mw->Scrolled( TextUndo => ... )->pack( ... )->Subwidget('scrolled');