#!/usr/bin/perl -w # 實驗各種 option 的效果. 此處以 -justify 與 -anchor 為例. # 當你遇到其他有疑問的 options 時, 不妨多多利用這個程式 (加以修改) 來實驗. use strict; my (%W); # use Tk; #=NIS=# # $W{_} = MainWindow->new(); #=NIS=# use Tcl::Tk qw(:perlTk); #=MBVK=# my $interp = Tcl::Tk->new(); #=MBVK=# $W{_} = $interp->mainwindow(); #=MBVK=# my ($v_just, $item); $W{_show} = $W{_}->Frame(); $W{_show}->pack(-side=>"left", -fill=>"both"); $W{_show_watchme} = $W{_show}->Label( -text=>"Effect\nOf justify\nAnd anchor", -width=>30, -height=>8, -bd=>2, -relief=>"groove" ); $W{_show_watchme}->pack(-side=>"top", -fill=>"both"); $W{_show_costr} = $W{_show}->Label(); $W{_show_costr}->pack(-side=>"top", -fill=>"both"); $W{_ctrl} = $W{_}->Frame(); $W{_ctrl}->pack(-side=>"left", -fill=>"both"); $W{_ctrl_action} = $W{_ctrl}->Button(-text=>"Change It!", -command=>\&change_it); $W{_ctrl_action}->pack(-side=>"top", -fill=>"both"); $W{_ctrl_just} = $W{_ctrl}->Frame(); $W{_ctrl_just}->pack(-side=>"top", -fill=>"both"); $v_just = "center"; foreach $item (qw(left center right)) { $W{"_ctrl_just_$item"} = $W{_ctrl_just}->Radiobutton( -value=>$item, -text=>$item, -variable=>\$v_just); $W{"_ctrl_just_$item"}->pack(-side=>"left", -fill=>"both"); } $W{_ctrl_anchor} = $W{_ctrl}->Listbox(); $W{_ctrl_anchor}->pack(-side=>"top", -fill=>"both"); $W{_ctrl_anchor}->insert(0, qw(nw n ne w center e sw s se)); $W{_ctrl_anchor}->selectionSet(4); MainLoop(); # ================================================================= sub change_it { my ($anchor) = $W{_ctrl_anchor}->get( $W{_ctrl_anchor}->curselection() ); $W{_show_costr}->configure(-text=>"-justify $v_just -anchor $anchor"); $W{_show_watchme}->configure(-justify=>$v_just, -anchor=>$anchor); }