TK Very Quick Reference

Widget Syntax


Widgets

Category Syntax
button button name -text "Text" -command { Tcl_code... }
canvas canvas name
name create arc x1 y1 x2 y2
checkbutton checkbutton name -text "Text" -variable varname \
-onvalue On -offvalue Off \
-command { Tcl_code... }
entry entry name -width 15 -textvariable foo

name delete 0 end
name insert end string
frame frame name -bd 2 -relief groove
label label name -text "Text"
listbox listbox name.list -height 10 -selectmode single \
-yscrollcommand "name.scroll set"
scrollbar name.scroll -command { name.list yview }
name.list insert "List item"
pack name.scroll -side right -fill y
pack name.list -side left
bind name.list <Double-Button-1> { Tcl_code... }
menu
and
menubutton
menubutton name -text "File" -menu name.menu \
-underline 0
menu name.menu
name.menu add command -label "Save" \
-underline 0 -command { Tcl_code... }
name.menu add separator
name.menu add cascade -label "Submenu" \
-menu name.menu.sub
name.menu add separator
name.menu add command -label "Exit" \
-underline 1 -command { exit }
pack name -side left
message message name -text "Text" -width 2c
radiobutton radiobutton name -text "Text" -variable varname \
-value "Print"
scale scale name -label "Text" -variable varname \
-length 300 -from 0 -to 255 -tickinterval 50 \
-orient horizontal -command { Tcl_code... }
text frame fr
ext fr.textname -yscrollcommand "scrollname set"
scrollbar fr.scrollname -command "textname yview"
pack fr.scrollname -side right -fill y
pack fr.textname -side left
pack fr

fr.textname insert 1.0 "Text to Insert"
fr.textname get 1.0 end
tk_dialog set result [tk_dialog name "Title" "Text" bitmap 0 OK Cancel]
tk_optionMenu tk_optionMenu name variablename \
value1 value2 value3 value4 …
tk_popup bind all { tk_popup name x y }
toplevel toplevel name
wm title name "Title"
wm geometry name +X+Y
wm protocol name WM_DELETE_WINDOW { Tcl_code... }

Widget Placement

Category Syntax
destroy destroy name
grid grid config name.l -column 0 -row 0 -sticky "e"
grid config name.r -column 1 -row 0 -sticky "snew"
pack pack name -side left -expand 1 -fill x
place place configure name -width 10c -height 1c
place configure name -anchor center
place configure name -anchor sw

Clipboard

Category Syntax
clipboard clipboard clear
clipboard append "Data"
selection get -selection CLIPBOARD
selection selection get -selection PRIMARY -type STRING
selection get -selection PRIMARY -type TARGETS
selection clear
set owner [selection own]