#!/usr/local/bin/perl -w
use Tk;
use strict;
my $command = ""; # text variable of entry
my @buttons = (); # list of command buttons
my $main = new MainWindow;
my $quit = $main->Button(
'-text' => "Quit",
'-command' => sub { exit },
);
$quit->pack('-fill' => 'x');
my $entry = $main->Entry('-textvariable' => \$command);
$entry->bind('<Control-u>', sub { $command = "" });
$entry->bind('<Return>',
sub { add_button($command); system($command); });
$entry->pack('-fill' => 'x');
MainLoop;
sub add_button {
my $cmd = shift;
my $button = $main->Button(
'-text' => $cmd,
'-command' => sub { system($cmd) },
);
$button->pack('-fill' => 'x');
push(@buttons, $button);
if (@buttons > 5) {
shift(@buttons)->destroy;
}
}
|