#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $vh = $mw->vrootheight; my $vw = $mw->vrootwidth; $mw->geometry($vw.'x'.$vh.'+0+0'); $mw->overrideredirect(1); #grabs full control $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=>int(-18*18/14)); my $topframe = $mw->Frame->pack(); my $frame = $mw->Frame->pack(); my $txt; #make these globals so you reuse them my $canvas; #and avoid memory gains of making too many #redundant widgets my $count = 0; # instead of a button you could make navigation arrows $topframe->Button(-text => "Change Screen", -command => sub{ #clean out frame's children my @w = $frame->packSlaves; foreach (@w) { $_->packForget; } #clean out frame $frame->packForget; $count++; &build($count); })->pack(-side=>'left',-padx=>20); $topframe->Button(-text => "Exit", -command => sub {exit})->pack(-side=>'right',-padx=>20); &build(0); #setup first screen MainLoop; sub build { my $count = shift; $txt = $frame->Text(-bg=>'white',-font=>'big',-height=>5)->pack(-fill=>'x'); $txt->insert('end',"\t\t\t\t Page $count"); # Note that the 'virtual window' height and width are $vh and $vw # respectively, so we use those dimensions for our Canvas height # and width, and let the Canvas expand and fill in both x and y # directions. # $canvas = $frame->Canvas( -width => $vw, -height => $vh, -background =>'blue', )->pack(-expand => 1, -fill => 'both'); $canvas->createRectangle(80, 80, 200, 200, -fill => 'yellow'); $canvas->createText(125, 125, -fill => 'black', -text => "page $count", -font => 'big', ); $frame->pack(); #reshow it $mw->update; }