What are you trying to clear? A Tk Canvas? Clear everything? If so,
$canvas->delete('all'); # all or the tag you want to delete
or are you trying to change focus. Be more specific.
| [reply] [d/l] |
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. | [reply] |
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();
| [reply] [d/l] |
Whenever you make a post you should provide as many details as possible. Without the details in the question, we don't have enough information to give you a detailed response.
I am assuming that you are using Tk? Keep in mind that there are other GUI toolkit's out there with their own canvas widgets.
If you want to give focus to a widget - use the grab method:
$canvas1->grab;
$canvas2->grab;
| [reply] [d/l] |