Edited at
TclDay 3

Tcl/TkでHello, world!


Tk編


タイトルでHello, world!


hello.tcl

wm title . "Hello, world!"



よくあるHello, world!


hello.tcl

pack [label .l -text "Hello, world!"]



細切れにHello, world!


hello.tcl

set buffer "Hello, world!"

set length [string length $buffer]
for {set i 0} {$i < $length} {incr i} {
lappend labels [label .l$i -text [string index $buffer $i]]
}
grid {*}$labels


ボタンを押したらHello, world!


hello.tcl

pack [button .b -text click! -command [list tk_messageBox -message "Hello, world!"]]



ダブルクリックでHello, world!


hello.tcl

pack [label .l -textvariable buffer]

bind . <Double-1> [list set buffer "Hello, world!"]


ちょっと遅れてHello, world!


hello.tcl

pack [label .l -textvariable buffer]

after 3000 [list set buffer "Hello, world!"]


閉じようとしたらHello, world!


hello.tcl

bind . <Destroy> [list tk_messageBox -message "Hello, world!"]