Updated 2014-06-04 05:40:52 by pooryorick (Redirected from Tk syntax help)

Tk Commands is a list of commands that are built-in to Tk.

Administration  edit

console
loadTk
tk

Data  edit

image
bitmap
photo

Dialogues  edit

tk_chooseColor
tk_chooseDirectory
tk_dialog
tk_getOpenFile
tk_getSaveFile
tk_messageBox

Event Management  edit

bind
bindtags
event
tkwait

Inter-Process Communication  edit

send

Facilities  edit

clipboard
tkerror

Fonts  edit

font

Geometry  edit

grid
pack
place

Control  edit

bell
grab
focus
selection
tk_focusNext
tk_focusPrev
tk_focusFollowsMouse
tk_menuSetFocus
palette
tk_bisque
tk_setPalette
tk_textCopy
tk_textCut
tk_textPaste

Reference  edit

colors
cursors
options
keysyms
tkvars

ttk  edit

In Tk 8.5, the Ttk package becomes a part of the Tk distribution. Special information on some of these tile/ttk widgets:
tk::classic::restore
ttk::combobox
ttk::scale

Variables  edit

Reserved variables are (incomplete):
tk_library
tk_strictMotif
tk_version

environment variables

There are also some environment variables.

Widgets  edit

button
canvas
checkbutton
entry
frame
label
labelframe
listbox
menu
menubutton
message
panedwindow
radiobutton
scale
scrollbar
spinbox
text
tk_optionMenu
tk_popup
toplevel
all the Ttk commands

Additional Widgets  edit

HTML widgets

tklib's widget package contains the following megawidgets:
dialog
(a)synchronous dialog shell with core dialog handling
menuentry
entry with dropdown menu
panelframe
ruler
screenruler
this is cool, really!
scrolledwindow
statusbar
for easier handling of bottom status items, with corner resize control
superframe
toolbar

Many third-party widgets are Snidgets. See that page for a list of Snidgets.

Window Management  edit

destroy
lower
option
raise
winfo
wm

Obsolete Widgets  edit

menubar
pack-old

** Internal Variables
::tk::psglyphs
::tk::ps_preamble
::tk::AlwaysShowSelection

Internal Commands  edit

::tk::ConsoleInvoke
::tk::ConsoleSource
::tk::ConsoleExit
::tk::ConsoleHistory
::tk::ensure_psenc_is_loaded
an empty procedure that can be called to auto-load the postscript features of Tk
::tk::CreatePostscriptEncoding
::tk::ps::literal
::tk::ps::variable
::tk::ps::function
::tk::SetFocusGrab
::tk::RestoreFocusGrab

See Also  edit

megawidget
Tcl syntax
Widgets in the initial Tk package
images of the various widgets.
Tk glossary
Explains some terms occurring in the manpages.
widget
general information widgets.
Tk widget sticky discussion

Misc  edit

Note that in Tk, one has several ways one can control visual aspects of widgets:

  • externally, via the X resource database
  • at creation time, on the command line
  • later, using the -config option
  • via the option database
  • in some cases, via special objects, like font

[are there other ways of influencing these?]

One must be certain to keep some things in mind when writing widget code:

  • Widget names are generally a series of period separated names. [Can someone write more text here concerning the naming of widgets, naming hierarchy and what is for, how it contrasts with namespaces, etc.]
  • If your widget names might have spaces in them, be certain to treat the names carefully, in particular when using eval, subst, etc.
  • DKF writes in comp.lang.tcl:

It's also not a good idea at all to start a widget name part with a capital letter (because that style of name is reserved for the names of widget classes, and you *really* don't want to get those two mixed up.) But it's usually really easy to start with a lower-case letter and use alphanumeric for the rest...

[Using :: as characters in a widgets name as a] problem is much more difficult to get around for megawidget authors than the space one. Properly treating things as lists solves the space problem. However, the use of namespaces for megawidget building is common in order to encapsulate code / hide the ickies from the user. That conflicts with the use of ::. It is possible to rename the :: parts when you use namespaces, but then it becomes cumbersome to map back and forth.

RS: As each widget defines a command with its name, can't interp aliases be used to map fancy to real names? E.g.
interp alias {} foo::bar {} .top.frame1.bar.canvas

LV: So, if someone has a string that they are certain is a name of a widget, is there introspection that can be used to determine what widget it is?

escargo 2005-08-16: I would expect winfo exists should be able to answer that question.

LV: winfo exists just tells me if the widget exists - not what kind of a widget it is. Thanks!

MG: How about winfo class $widgetName?

LV: That seems like it should work - thanks!

RS 2006-04-28: Here's a little helper to retrieve the default value of a widget attribute (use long names (-background) instead of the short ones (-bg)):
% proc get'default {w flag} {lindex [$w config $flag] 3}
% get'default $t -font
{MS Sans Serif} 8

The current value is of course returned by the cget method:
% $t cget -font
Courier 9