Buttons & Entries

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

cmds.pl
#!/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;
   }
}

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996, 1998, 1999, 2000 Andreas Borchert, in HTML konvertiert am 07.02.2000