use Tk; use Tk::PNG; use strict; use warnings; use FindBin; my $main = new MainWindow; our $DiagramWin; our $DiagramWin_open = 0; my $butShow1 = $main -> Button(-text=>" Show 1 ", -command =>\&butShow1_clicked) ->pack(-side => 'top'); my $butShow2 = $main -> Button(-text=>" Show 2 ", -command =>\&butShow2_clicked) ->pack(-side => 'top'); my $butQuit = $main -> Button(-text=>" Close ", -command =>\&DiagramWin_close) ->pack(-side => 'top'); MainLoop; sub butShow1_clicked { &DiagramWin_show("wetterdiagramm1.png") }; sub butShow2_clicked { &DiagramWin_show("wetterdiagramm2.png") }; sub DiagramWin_show { my $png_filename = shift; if ($DiagramWin_open eq 0) { $DiagramWin = $main -> Toplevel (-title=> "Unterfenster", -width=>1024, -height=>768); $DiagramWin -> OnDestroy(\&DiagramWin_destroyed); } my $canv = $DiagramWin -> Canvas(-width => 1024, -height => 768, -background => 'dark slate gray')->pack; my $diagram = $FindBin::Bin . "/" . $png_filename; $canv -> create ('image', 0, 0, -image => $main->Photo(-file=> $diagram), -anchor => 'nw'); $DiagramWin_open = 1; } sub DiagramWin_close { if ($DiagramWin_open) { $DiagramWin -> destroy(); } $DiagramWin_open = 0; } sub DiagramWin_destroyed { $DiagramWin_open = 0; }