use warnings;
use strict;
use Tk;

# Das mw erzeugen
my $mw = MainWindow->new();
$mw->Label(-text => '     Test für Checkbutton     ')->pack();

my $status = '';
my $label = $mw->Label(-relief => 'ridge',
                       -textvariable => \$status);
$label->pack(-padx => 10, -pady => 10);

# declaration of the used variables

# einfacher  checkbutton
my $c1_value = "I am ready";    # predifined on
my $c1 = $mw->Checkbutton(-text  => "Are You Ready",
#                          -command  => sub { $status = "c1: $c1_value" },
                          -state    => "normal",  # Start "off"
                          -variable => \$c1_value,
                          -onvalue  => "I am ready",
                          -offvalue => "I am not ready");

# checkbutton mit dynamischem text
my $now = localtime(time);
my $c2_value = $now;
my $c2 = $mw->Checkbutton(-textvariable => \$now,
                          -anchor       => "w",
                          -command      => sub { $now = localtime(time) },
                          -state        => "active",  # Start "on"
                          -variable     => \$c2_value,
                          -onvalue      => $now,
                          -offvalue     => "No time");

# die folgenden beiden sind miteinander verknuepft
my $c3_value = "OFF";
my $c3 = $mw->Checkbutton(-text     => "verknuepft mit dem folgenden Button",
                         -anchor   => "w",
                         -variable => \$c3_value,
                         -onvalue  => "ON",
                         -offvalue => "OFF");
my $c4 = $mw->Checkbutton(-text     => "verknuepft mit dem vorhergehenden Button",
                          -anchor   => "w",
                          -variable => \$c3_value,
                          -onvalue  => "ON",
                          -offvalue => "OFF");
# mal wieder einen Exit-Button
my $c5 = $mw->Button(-text     => "Exit",
                     -command  => sub { exit 0 });

# alles Packen
$c1->pack(-anchor => 'w', -fill => 'x');
$c2->pack(-anchor => 'w', -fill => 'x');
$c3->pack(-anchor => 'w', -fill => 'x');
$c4->pack(-anchor => 'w', -fill => 'x');
$c5->pack(-fill => 'both', -expand => 1);

# Alle Werte ständig updaten
$mw->repeat(200,sub {$status = "C1: $c1_value, C2: $c2_value, C3: $c3_value"; });

MainLoop;
