For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > March 2007 > Re: Canvas Layering Images









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Canvas Layering Images
zentara

2007-03-25, 7:01 pm

Hi,

I've been trying to reply to the guy who said the layering
of images on canvases was broken.

I tried 3 times to reply, and they didn't go thru, possibly
because they included base64encoded images for
convenience.

Anyways, sorry for multiple posts of this, if you received them all.
This will be my last attempt, and I removed the
inlined images. (Damn windows and their virus prone system).

Back to the point, your problem may be that you are
using a scrolled canvas. Tag lowering and raising must
be done on the real canvas, obtained from the Scrolled subwidget.

Here's a simple example, provide your own bunny and tux images.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::JPEG;
use Tk::PNG;

#demonstrates need for subwidget method
#on Scrolled Canvas, to use lower or raise

my $mw = new MainWindow;

my $canvas = $mw->Scrolled('Canvas',
-bg => 'white',
-xscrollincrement => 1,
-yscrollincrement => 1,
-confine => 1,
-scrollbars => 'se',
-width => 200,
-height => 200,
-closeenough =>3,
-scrollregion => [ 0, 0, 500, 500 ],
)->pack(qw/ -fill both -expand 1 -side top/);


my $realcanvas = $canvas->Subwidget('scrolled');

$mw->Button(-text=>"Raise Bunny",
-command => sub{
# $canvas->lower( 'bunny' ,'tux' ); # will cause error
# need subwidget of the scrolled canvas

$realcanvas->raise( 'bunny' ,'tux' );
})->pack();

$mw->Button(-text=>"Lower Bunny",
-command => sub{
$realcanvas->lower( 'bunny' ,'tux' );
})->pack();



my $tux = $mw->Photo(-file => 'tux.jpg' );

$canvas->createImage( 0, 0, -image => $tux,
-anchor => 'nw',
-tags => ['tux'],
);

my $bunny = $mw->Photo(-file => 'bunny.jpg' );
$canvas->createImage( 40, 40, -image => $bunny,
-anchor => 'nw',
-tags => ['bunny'],
);


my $lineseg = $canvas->createLine(
1,1,200,200,
-fill => 'red',
-tags => ['line']
);

# $canvas->lower( 'bunny' ,'tux' ); # will cause error
# need subwidget
$realcanvas->lower( 'bunny' ,'tux' );

MainLoop;
__END__


zentara

--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com