in reply to Re: Which tk to use and how to show images?
in thread Which tk to use and how to show images?
I think you are going to run into problems with this type of script, where you combine Tk and GD.
Hmm. Provided that you disard old things before creating new ones, the space should be reused.
I haven't put this in a tight loop and run it thousands of times, but I've clicked the button quite a lot (maybe a 100 times) whilst monitoring the memory, and I see no sign of a growth trend (on my system):
use Tk; use Tk::PNG; use MIME::Base64; use GD::Graph; use GD::Graph::bars; my $data = [ [qw/1st 2nd 3rd 4th 5th 6th 7th 8th 9th/], [qw/ 1 2 5 6 3 1.5 1 3 4/], ]; my $graph = GD::Graph::bars->new(400, 300); $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_tick_number => 8, y_label_skip => 2 ) or die $my_graph->error; my $gd = $graph->plot($data) or die $my_graph->error; my $mw = MainWindow->new; my $png = $mw->Photo(-data => encode_base64($gd->png)); $mw->Button( -text => 'doit', -command => sub{ $data->[ 1 ] = [ map{ rand 5 } 1 .. 9 ]; undef $graph; $graph = GD::Graph::bars->new(400, 300); $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_tick_number => 8, y_label_skip => 2 ) or die $my_graph->error; my $gd = $graph->plot($data) or die $my_graph->error; $png->blank; $png->configure( -data => encode_base64($gd->png) ); $mw->update; } )->pack; $mw->Label(-image => $png)->pack; MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Which tk to use and how to show images?
by zentara (Cardinal) on Nov 04, 2005 at 17:40 UTC | |
by BrowserUk (Patriarch) on Nov 04, 2005 at 17:44 UTC | |
by rcseege (Pilgrim) on Nov 04, 2005 at 17:51 UTC | |
by BrowserUk (Patriarch) on Nov 04, 2005 at 17:58 UTC | |
by zentara (Cardinal) on Nov 05, 2005 at 12:49 UTC | |
by rcseege (Pilgrim) on Nov 04, 2005 at 18:19 UTC | |
| |
|
Re^3: Which tk to use and how to show images?
by Sinatra (Novice) on Nov 14, 2005 at 14:10 UTC |