#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11163827 use warnings; use Tk; my ($red, $green, $blue) = (0, 50, 100); my %colorhash = (Red => \$red, Green => \$green, Blue => \$blue); my $mw = MainWindow->new; $mw->geometry( '300x100+500+400' ); my $row = 1; for ( qw( Red Green Blue ) ) { $mw->Label(-text => $_, )->grid(-row => $row, -column => 1, -sticky => 'w'); $mw->Label(-textvariable => $colorhash{$_}, )->grid(-row => $row++, -column => 2, -sticky => 'e'); } my $color = 0; $mw->repeat( 1000, \&change ); $mw->repeat( 1777, sub {-M $0 < 0 and exec $0}); # restart when code changes MainLoop; sub change { ( sub { $red = int rand 50 }, sub { $green = 50 + int rand 50 }, sub { $blue = 100 + int rand 50 } )[ $color = ( $color + 1 ) % 3 ](); }