[ Team LiB ] Previous Section Next Section

The tk Command

The tk command provides a few miscellaneous entry points into the Tk library.

The appname operation is used to set or query the application name used with the Tk send command. If you define a new name and it is already in use by another application, (perhaps another instance of yourself), then a number is appended to the name (e.g., #2, #3, and so on). This is the syntax of the command:

tk appname ?name?

Fonts, canvas items, and widget sizes use screen units that are pixels, points, centimeters, millimeters, or inches. There are 72 points per inch. The tk scaling command, which was added in Tk 8.0, is used to set or query the mapping between pixels and points. A scale of 1.0 results in 72 pixels per inch. A scale of 1.25 results in 90 pixels per inch. This gives accurate sizes on a 90 dpi screen or it makes everything 25% larger on a 72 dpi screen. Changing the scale only affects widgets created after the change. This is the syntax of the command:

tk scaling ?num?

graphics/common_icon.gif

Determining the windowing system.


The tk windowingsystem command, added in Tk 8.4, returns one of x11 (X11-based), win32 (MS Windows), classic (Mac OS Classic), or aqua (Mac OS X Aqua). Traditionally, Tk applications that included platform-dependent code could simply switch on the value of the global tcl_platform(platform) element, which is set to macintosh, unix, or windows. But the introduction of Apple's OS X and the Aqua interface complicated matters. Mac OS X reports unix in the tcl_platform(platform) element. But its windowing system is not a native X Windows system, so you must use tk windowingsystem.

The caret operation, introduced in Tk 8.4, sets and queries the caret location for the display of the specified Tk window. The caret is the per-display cursor location used for indicating global focus (for example, to comply with Microsoft Accessibility guidelines), as well as for location of the over-the-spot XIM (X Input Methods) or Windows IME windows.

The useinputmethods operation changes the behavior of Tk on X with X Input Methods (XIM). Before Tk 8.3, XIM was recognized and used without question. As of Tk 8.3, they are recognized and initialized, but not used unless XIM is turned on with the useinputmethods operation:

tk useinputmethods 1

Table 44-12 summarizes the tk command operations:

Table 44-12. The tk command operations

tk appname ?name?

Queries or sets the application name, used by the Tk send command.

tk caret window ?-x x? ?-y y? ?-height height?

Queries or sets the caret location for the display of the specified Tk window. x and y represent window-relative coordinates. height is the height of the current cursor location, or the height of the specified window. Values are returned in option-value pair format. (Tk 8.4)

tk scaling ?-displayof window? ?number?

Queries or sets the current scaling factor used by Tk to convert between physical units and pixels. number is a floating point value that specifies the number of pixels per point on window's display. If window is omitted, it defaults to the main window. If number is omitted, the current value of the scaling factor is returned.

tk useinputmethods ?-displayof window? ?boolean?

Queries or sets the state of whether Tk should use XIM (X Input Methods) for filtering events. The resulting state is returned. If XIM support is not available, this will always return 0. If window is omitted, it defaults to the main window. If boolean is omitted, the current state is returned. (Tk 8.3)

tk windowingsystem

Returns the current windowing system: x11 (X11-based), win32 (MS Windows), classic (Mac OS Classic), or aqua (Mac OS X Aqua). (Tk 8.4)

    [ Team LiB ] Previous Section Next Section