1console(n) Tk Built-In Commands console(n)
2
3
4
5______________________________________________________________________________
6
8 console - Control the console on systems without a real console
9
11 console subcommand ?arg ...?
12______________________________________________________________________________
13
15 The console window is a replacement for a real console to allow input
16 and output on the standard I/O channels on platforms that do not have a
17 real console. It is implemented as a separate interpreter with the Tk
18 toolkit loaded, and control over this interpreter is given through the
19 console command. The behaviour of the console window is defined mainly
20 through the contents of the console.tcl file in the Tk library. Except
21 for TkAqua, this command is not available when Tk is loaded into a
22 tclsh interpreter with “package require Tk”, as a conventional terminal
23 is expected to be present in that case. In TkAqua, this command is
24 disabled when there is a startup script and stdin is /dev/null (as is
25 the case e.g. when a bundled application embedding Tk is started by the
26 macOS Launcher). To enable the command in that case, define the envi‐
27 ronment variable TK_CONSOLE. This can be done by modifying the
28 Info.plist file by adding the LSEnvironment key to the main dict and
29 setting its value to be a dict with the key TK_CONSOLE.
30
31 console eval script
32 Evaluate the script argument as a Tcl script in the console in‐
33 terpreter. The normal interpreter is accessed through the con‐
34 soleinterp command in the console interpreter.
35
36 console hide
37 Hide the console window from view. Precisely equivalent to
38 withdrawing the . window in the console interpreter.
39
40 console show
41 Display the console window. Precisely equivalent to deiconify‐
42 ing the . window in the console interpreter.
43
44 console title ?string?
45 Query or modify the title of the console window. If string is
46 not specified, queries the title of the console window, and sets
47 the title of the console window to string otherwise. Precisely
48 equivalent to using the wm title command in the console inter‐
49 preter.
50
52 The consoleinterp command in the console interpreter allows scripts to
53 be evaluated in the main interpreter. It supports two subcommands:
54 eval and record.
55
56 consoleinterp eval script
57 Evaluates script as a Tcl script at the global level in the main
58 interpreter.
59
60 consoleinterp record script
61 Records and evaluates script as a Tcl script at the global level
62 in the main interpreter as if script had been typed in at the
63 console.
64
66 There are several additional commands in the console interpreter that
67 are called in response to activity in the main interpreter. These are
68 documented here for completeness only; they form part of the internal
69 implementation of the console and are likely to change or be modified
70 without warning.
71
72 Output to the console from the main interpreter via the stdout and
73 stderr channels is handled by invoking the tk::ConsoleOutput command in
74 the console interpreter with two arguments. The first argument is the
75 name of the channel being written to, and the second argument is the
76 string being written to the channel (after encoding and end-of-line
77 translation processing has been performed.)
78
79 When the . window of the main interpreter is destroyed, the tk::Con‐
80 soleExit command in the console interpreter is called (assuming the
81 console interpreter has not already been deleted itself, that is.)
82
84 The default script creates a console window (implemented using a text
85 widget) that has the following behaviour:
86
87 [1] Pressing the tab key inserts a TAB character (as defined by the
88 Tcl \t escape.)
89
90 [2] Pressing the return key causes the current line (if complete by
91 the rules of info complete) to be passed to the main interpreter
92 for evaluation.
93
94 [3] Pressing the delete key deletes the selected text (if any text
95 is selected) or the character to the right of the cursor (if not
96 at the end of the line.)
97
98 [4] Pressing the backspace key deletes the selected text (if any
99 text is selected) or the character to the left of the cursor (of
100 not at the start of the line.)
101
102 [5] Pressing either Control+A or the home key causes the cursor to
103 go to the start of the line (but after the prompt, if a prompt
104 is present on the line.)
105
106 [6] Pressing either Control+E or the end key causes the cursor to go
107 to the end of the line.
108
109 [7] Pressing either Control+P or the up key causes the previous en‐
110 try in the command history to be selected.
111
112 [8] Pressing either Control+N or the down key causes the next entry
113 in the command history to be selected.
114
115 [9] Pressing either Control+B or the left key causes the cursor to
116 move one character backward as long as the cursor is not at the
117 prompt.
118
119 [10] Pressing either Control+F or the right key causes the cursor to
120 move one character forward.
121
122 [11] Pressing F9 rebuilds the console window by destroying all its
123 children and reloading the Tcl script that defined the console's
124 behaviour.
125
126 Most other behaviour is the same as a conventional text widget except
127 for the way that the <<Cut>> event is handled identically to the
128 <<Copy>> event.
129
131 Not all platforms have the console command, so debugging code often has
132 the following code fragment in it so output produced by puts can be
133 seen while during development:
134 catch {console show}
135
137 destroy(n), fconfigure(n), history(n), interp(n), puts(n), text(n),
138 wm(n)
139
141 console, interpreter, window, interactive, output channels
142
143
144
145Tk 8.4 console(n)