my $viewbutton = $mw->Button(-text=>"Change view", -command=>\&changeView); ... sub changeView { $viewmode++; if($viewmode > 3) { $viewmode = 0; } updateGraph(); return; }