widget .path ?-opt1 -opt2 -opt3 ...? =>.path .path subcmd ?-opt1 -opt2 -opt3 ...? |
それでは、簡単なサンプルを見てください。
日本語を使う場合は、Tcl8.1以上をお使いください。
pack [button .b -text ボタン -command exit] |
set var ボタン pack [button .b -textvariable var -command exit] |
set みかん 1; set バナナ 1 foreach item {りんご みかん バナナ} { checkbutton .cb$item -text $item -variable $item pack .cb$item -side left } |
set choice みかん foreach item {りんご みかん バナナ} { radiobutton .cb$item -text $item -variable choice -value $item pack .cb$item -side left } |
pack [label .l -text ラベル] |
set var ラベル pack [label .l -textvariable var] |
set var デフォルト pack [entry .e -textvariable var] |
pack [spinbox .sb -from 1 -to 10 -textvariable var -increment 1 -wrap yes] |
pack [listbox .l -exportselection 0] .l insert end りんご みかん バナナ .l selection set 0 |
# Tk8.3から-listvarオプションが使える set var {りんご みかん バナナ} pack [listbox .l -exportselection 0 -listvar var] .l selection set 0 |
pack [text .t] .t insert end "りんご\nみかん\nバナナ" |
pack [scrollbar .s -orient horizontal] |
pack [scale .s -label ラベル -from 0 -to 100 -length 100 \ -variable var -orient horizontal -tickinterval 50 -showvalue true] |
pack [frame .f -bd 2 -relief groove -width 100 -height 50] |
pack [labelframe .f -text ラベル -bd 2 -relief groove -width 100 -height 50] |
pack [panedwindow .p -orient horizontal] label .p.l1 -text Left -width 10 label .p.l2 -text Right -width 10 .p add .p.l1 .p.l2 |
pack [message .m -justify left -text {これは長いメッセージです。\ 一行で書けない時は、バックスラッシュで改行します。}] |
pack [canvas .c] .c create oval 10 10 40 40 -fill red -width 4 .c create oval 30 10 60 40 -fill green -width 4 .c create oval 20 30 50 60 -fill blue -width 4 |
toplevel .main wm transient .main [winfo toplevel [winfo parent .main]] wm resizable .main no no wm protocol .main WM_DELETE_WINDOW exit wm withdraw . pack [label .main.l -text "トップレベル"] |
menu .menu .menu add cascade -label ファイル -menu .menu.file .menu add cascade -label 編集 -menu .menu.edit .menu add cascade -label 表示 -menu .menu.view menu .menu.file -tearoff no .menu.file add command -label 終了 -command exit . configure -menu .menu |
frame .m pack .m -side top -fill x menubutton .m.file -text ファイル -menu .m.file.menu menubutton .m.edit -text 編集 menubutton .m.view -text 表示 pack .m.file .m.edit .m.view -side left menu .m.file.menu -tearoff 0 .m.file.menu add command -label 終了 -command exit |
tk_optionMenu .o var りんご みかん バナナ pack .o |
menu .popup -tearoff no .popup add command -label "開く..." -accelerator "Ctrl+O" .popup add command -label "保存..." -accelerator "Ctrl+S" .popup add separator .popup add command -label "終了..." -accelerator "Ctrl+W" -command exit bind . <3> { tk_popup .popup %X %Y } |
tk_messageBox -type ok -title メッセージボックス -icon info \ -message メッセージです。 |
after 10 { wm withdraw .dlg set x [expr [winfo rootx .] + 20] set y [expr [winfo rooty .] + 20] wm geometry .dlg +$x+$y wm deiconify .dlg wm resizable .dlg no no wm protocol .dlg WM_DELETE_WINDOW {destroy .dlg} .dlg.msg configure -text ラベル } tk_dialog .dlg ダイアログ {} {} 0 OK キャンセル |
set types { { "Text" {.txt} } } set file [tk_getOpenFile -filetypes $types -title 開く] |
set types { { "Text" {.txt} } } set file [tk_getSaveFile -filetypes $types -title 保存 -defaultextension .txt] |
set dir [tk_chooseDirectory -title ディレクトリ] |
set color [tk_chooseColor -title カラー] |