in reply to Re: Tk: Scaling canvas objects
in thread Tk: Scaling canvas objects

Oh, the image only zooms because I deal with it separately by redrawing the image at the appropriate scale every time the canvas is zoomed.

#####----- Show zoomed picture -----##### # $zoom is number between -4 and 3; Negative for zoom-out and positiv +e for zoom-in as worked out in the conditional statement. # $img is the original image. # $zimg is the zoomed image. $zimg = $MW->Photo(); ($zoom > 0) ? $zimg->copy($img, -zoom => $zoom) : $zimg->copy($img, -subsample => ($zoom * -1)); $CW->createImage(0,0, -anchor => 'nw', -image => $zimg, -tags => 'dwg' +);

It's just the object scaling (that I try to do with $CW->scale()) that doesn't work and that gives me the aforementioned error.

I'll try out your code (assuming it's tested) to ensure there is nothing wrong with my Tk. If there isn't I'm going to take the non-essential stuff out of my code and if it still doesn't work, I'll post it here!

Thanks,

Perldough

Replies are listed 'Best First'.
Re^3: Tk: Scaling canvas objects
by zentara (Cardinal) on Jul 24, 2012 at 13:36 UTC
    I'll try out your code (assuming it's tested)

    Yes, it's well tested standard code. If you want to zoom text, you can configure the font object to use a scaled up point size. Rebuilding the font, just as you rebuild a new image.

    #!/usr/bin/perl use warnings; use strict; use Tk; require Tk::Font; #by originally by Chris Lamprecht my $MAIN = new MainWindow; my $canvas = $MAIN->Canvas()->pack(-expand => 'yes', -fill =>'both'); my $initial_fontsize = 24; my $scaling_factor = 1; my $l_text = "current scaling_factor : $scaling_factor"; my $helveticaStd = $MAIN->Font(-family=> 'Arial', -size => $initial_ +fontsize); my $text = 'This is some text'; $canvas->createText(50,50, -text => $text, -anchor => 'nw', -font => $helveticaStd); $canvas->createRectangle(47,47,290,87); for my$fac (0.8,1.2){ $MAIN->Button(-text => "Scale by $fac", -command => [\&scaling,$fac] )->pack; } $MAIN->Label(-textvariable=>\$l_text)->pack; MainLoop; sub scaling{ $scaling_factor *= $_[0]; $canvas->scale('all',0,0,$_[0],$_[0]); $helveticaStd->configure(-size=>$initial_fontsize * $scaling_factor +); $l_text = "current scaling_factor : $scaling_factor"; } __END__

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