#!/usr/bin/perl -w
# 實驗各種 option 的效果. 此處以 -bg, -text, 與 -bd 為例.
# 當你遇到其他有疑問的 options 時, 不妨多多利用這個程式 (加以修改) 來實驗.

use Tk;
use strict;

my ($main);

$main = MainWindow->new();

$main->{bd} = $main->Scale(-orient=>"horizontal",
    -from=>0, -to=>50, -length=>200, -command=>\&change_bd);
$main->{watchme} = $main->Label(-relief=>"ridge", -text=>"<no files selected>");
$main->{bg} = $main->Button(-text=>"-bg", -command=>\&change_bg);
$main->{text} = $main->Button(-text=>"-text", -command=>\&change_text);

$main->{bd}->pack(-side=>"bottom", -fill=>"both");
$main->{watchme}->pack(-side=>"left", -fill=>"both");
$main->{bg}->pack($main->{text}, -side=>"top", -fill=>"both");

$main->configure(-bg=>"yellow");

MainLoop();

# =================================================================

sub change_bd {
    $main->{watchme}->configure(-bd=>$_[0]);
}

sub change_bg {
    my ($color) = $main->{watchme}->cget("-bg");
    $color = $main->chooseColor(-initialcolor=>$color);
    return unless defined $color;
    $main->{watchme}->configure(-bg=>$color);
}

sub change_text {
    my ($fn) = $main->getOpenFile();
    return unless defined $fn;
    $main->{watchme}->configure(-text=>$fn);
}

