in reply to canvas unselect

Yes im trying to change the focus. I dont want to delete the contents of the canvas just allow one canvas at a time to be highlighted and selected.

Replies are listed 'Best First'.
Re^2: canvas unselect
by zentara (Cardinal) on Dec 31, 2008 at 16:42 UTC
    Well you don't show any code, but here is something to play with. Tab around the widgets, or force focus to a canvas. Otherwise, show a minimal working code example, and say what you want it to do.
    #!/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();

    I'm not really a human, but I play one on earth Remember How Lucky You Are