in reply to Re: canvas unselect
in thread canvas unselect
#!/usr/bin/perl use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry('400x250'); my $mwf = $mw->Scrolled('Pane', -scrollbars=>'osoe', -sticky=>'nwse', )->pack(-expand=>1, -fill=>'both'); my $f1 = $mwf->Frame()->pack(); my $f2 = $mwf->Frame()->pack(); my %canv; for (0..4){ $canv{$_}{'obj'} = $f1->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left' ,-padx=>10,-pady=>10); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); my $num = $_; $canv{$num}{'obj'}->CanvasBind( '<FocusOut>' => sub{ $canv{$num}{'obj'}->configure(-bg=>'lightyellow'); } ); $canv{$num}{'obj'}->CanvasBind( '<FocusIn>' => sub{ $canv{$num}{'obj'}->configure(-bg=>'lightgreen'); } ); } for (5..9){ $canv{$_}{'obj'} = $f2->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); my $num = $_; $canv{$num}{'obj'}->CanvasBind( '<FocusOut>' => sub{ $canv{$num}{'obj'}->configure(-bg=>'lightyellow'); } ); $canv{$num}{'obj'}->CanvasBind( '<FocusIn>' => sub{ $canv{$num}{'obj'}->configure(-bg=>'lightgreen'); } ); } my $button = $mw->Button(-text=>'Focus 1', -command => sub{ $canv{1}{'obj'}->focusForce; $canv{1}{'obj'}->configure(-bg=>'blue'); })->pack(); MainLoop();
|
|---|