man n options
3-3 複数ウィジットの配置
何も考えない場合はウィジットは pack コマンドで指定した順に上から配置さ
れる。
% label .lab1 -text "Full name?"
.lab1
% button .b1 -text "YMCA" -command {
puts "Young Men's Christian Assosiation" }
.b1
% button .b2 -text "YMO" -command { puts "Yellow Magic Orchestra" }
.b2
% button .b3 -text "WTO" -command { puts "World Trade Organization" }
.b3
% button .b4 -text "EXIT" -command exit
.b4
% pack .lab1 .b1 .b2 .b3 .b4
"Full name?" という文字列と 4つのボタンを配置してみた。最後のボタンは終
了ボタンである。pack コマンドにオプション -side left を付けると、ウィ
ジットは横に並ぶ。
一部だけを横に並べたい場合は、frame ウィジットを作り、横に並べるウィジッ
トをその中に配置する。
% label .lab1 -text "Full name?"
.lab1
% frame .buttons
.buttons
% button .buttons.b1 -text "YMCA" -command {
puts "Young Men's Christian Assosiation" }
.buttons.b1
% button .buttons.b2 -text "YMO" -command {
puts "Yellow Magic Orchestra" }
.buttons.b2
% button .buttons.b3 -text "WTO" -command {
puts "World Trade Organization" }
.buttons.b3
% button .b4 -text "EXIT" -command exit -fill x
.b4
% pack .buttons.b1 .buttons.b2 .buttons.b3 -side left -padx 10
% pack .lab1 .buttons .b4 -pady 10 -fill x
.buttons という frame ウィジットの中に 3つのボタンを配置した。横に並べ
るために、オプション "-side left" を使った。また、間隔を空けるために
"-padx 10"というオプションを使った。さらに label ウィジット .lab1 と
frame ウィジット .buttons と button ウィジット .b4 を縦に並べた。縦方
向の間隔を空けるために、"-pady 10"というオプションを使った。"-fill x"