http://www.perlmonks.org?node_id=1002296


in reply to Re^2: How to destroy and re-create bound widgets
in thread How to destroy and re-create bound widgets

It sounds like you, as a beginner, my want to reconsider your design. The first thing I have to say, is why do you need the overlapping secondary sub-canvases? If you can make something on your sub-canvas, you can do the same thing on the underlying canvas. You can still put a background image on the main canvas, then instead of overlaying other canvases, why not create rectangular regions on the base canvas? In any event, look at this example:
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; my $main = $mw -> Scrolled("Canvas",-scrollbars=>'e')-> pack(-side =>'left', -fill => 'both', -expand => 1); my $canvas = $main->Subwidget("canvas"); Tk::bind($canvas, '<MouseWheel>', [ sub {$canvas->yview('scroll', -($_[1] / 120) * 3,'units')}, Ev('D')]); my $see = "\nHaaa, See that and scroll!"; my $info = $main->createText(180, 15, -text => "$see", -font => 'Arial 11 bold' , -fill => 'red'); $main->configure(-scrollregion => [0,0,2000 , 2000]); my $canvas_cube = $main->Canvas(-width => 45, -height => 45, -background => 'green'); my $canvasWindow = $main->createWindow(75,75, -window => $canvas_cube) +; Tk::bind( $canvas_cube, '<Enter>' => sub { print "Enter\n"; }); Tk::bind( $canvas_cube, '<Leave>' => sub { print "Leave\n"; }); Tk::bind( $canvas_cube, '<Button-1>' => sub { print "1\n"; }); $canvas->focus; MainLoop;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^4: How to destroy and re-create bound widgets
by zentara (Archbishop) on Nov 05, 2012 at 11:32 UTC