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

use Tk;
use strict;

my ($main, $v_just, $item);

# initialization script: 畫面左半是 .show, 右半是 .ctrl
$main = MainWindow->new();

    $main->{show} = $main->Frame();
	$main->{show}{watchme} = $main->{show}->Label(
	    -text=>"Effect\nOf justify\nAnd anchor",
	    -width=>30, -height=>15, -bd=>2, -relief=>"groove");
	$main->{show}{costr} = $main->{show}->Label();
    $main->{show}{watchme}->pack($main->{show}{costr}, -side=>"top", -fill=>"both");

    $main->{ctrl} = $main->Frame();
	$main->{ctrl}{action} = $main->{ctrl}->Button(
	    -text=>"Change It!", -command=>\&change_it);
	$main->{ctrl}{just} = $main->{ctrl}->Frame();
	$v_just = "center";
	foreach $item (qw(left center right)) {
	    $main->{ctrl}{just}{$item} = $main->{ctrl}{just}->Radiobutton(
		-value=>$item, -text=>$item, -variable=>\$v_just);
	    $main->{ctrl}{just}{$item}->pack(-side=>"left", -fill=>"both");
	}
	$main->{ctrl}{anchor} = $main->{ctrl}->Listbox();
	$main->{ctrl}{anchor}->insert(0, qw(nw n ne w center e sw s se));
	$main->{ctrl}{anchor}->selectionSet(4);
    $main->{ctrl}{action}->pack($main->{ctrl}{just}, $main->{ctrl}{anchor}, -side=>"top", -fill=>"both");

$main->{show}->pack($main->{ctrl}, -side=>"left", -fill=>"both");

MainLoop();

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

sub change_it {
    my ($anchor) = $main->{ctrl}{anchor}->get(
	$main->{ctrl}{anchor}->curselection()
    );
    $main->{show}{costr}->configure(-text=>"-justify $v_just -anchor $anchor");
    $main->{show}{watchme}->configure(-justify=>$v_just, -anchor=>$anchor);
}

