Appendix A. Tk Widget Reference

The least flexible component of any system is the user.

Lowell Jay Arthur

This appendix covers the most commonly used properties and methods of Tk widgets. Please refer to the extensive online documentation accompanying the Tk distribution for more details.

Table A.1 shows all the properties and methods shared by almost all widgets.

Table A-1. Generic Widget Properties

Properties

Description

font

Discussed in Section 14.3.1.1.

background, foreground

A name (“red”) or an RGB value (“#FF00FA”). The options can also be abbreviated to bg and fg. Discussed in Section 14.3.1.3.

text

The string to be displayed inside the widget. This is displayed in the foreground color in the font specified above.

image, bitmap

Specifies a bitmap to be displayed inside the widget. Refer to the section Section 14.3.1.2 for a discussion on creating and managing bitmaps.

relief

Border style: one of raised, sunken, flat, ridge, or groove. Should be accompanied by a nonzero borderwidth option.

height, width

Typically the height and width in pixels, except for labels, buttons, and text widgets, in which it is in number of characters (a multiple of average character width and height in that widget’s font).

textvariable

Specifies the name of a variable. When the value of a widget changes, this variable is updated, and vice versa.

anchor

Specifies how the widget or the information within it is positioned. Must be one of n, ne, e, se, s, sw, w, nw, or center. For ...

Get Advanced Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.