beetlebug▾
/

canvas focus

Gives or sets the item that gets the keys.

PATHNAME focus ?TAGORID?

Description

With TAGORID, gives the focus of the canvas to the first item of TAGORID that has text, and an empty TAGORID removes it. With no argument, gives the ID of the item with the focus, or an empty string. The canvas itself needs the focus of focus to get keys.

Returns

An item ID or an empty string with no argument, else an empty string.

Examples

% canvas .fo
> .fo create text 10 10 -text Name
> .fo focus 1
> .fo focus
1

# A rectangle has no text, so it cannot get the focus.
% canvas .fo2
> .fo2 create rectangle 0 0 10 10
> .fo2 focus 1
> .fo2 focus

Errors

% canvas .fo3; .fo3 focus a b
wrong # args: should be ".fo3 focus ?tagOrId?"
-errorcode NONE

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also