Welcome, guest | Sign In | My Account | Store | Cart

The following 14-command codelet gives you a window with entry and text widget, where you type commands into the entry, hit Return, and get the results (or error message) of evaluating the entry content in the text widget.

Tcl, 12 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
entry .e -textvar cmd
bind .e <;Key-Return>; {go %W}
text .t -wrap word
proc go {w} {
    global cmd
    .t insert end "% $cmd\n"
    catch {eval $cmd} res
    .t insert end $res\n
    set cmd ""
}
eval pack [winfo children .] -fill both -expand 1
focus .e

which allows you to source any file and call any Tcl command you might want. Of course, this can be expanded with colors to distinguish stdin/out/err, an entry with a history, menus, whatever.

But, in all simplicity, this requires the user to know what he's doing. Nothing prevents this code from evaluating "exec format c:"...

Tk for Windows has a built-in console that you can have come up just with the command <pre> console show </pre> See also the http://www.purl.org/thecliff/tcl/wiki/786.html console for Unix for a more elaborated console by Donald Porter href="http://www.purl.org/thecliff/tcl/wiki/93.html.

People not requiring something lightweight might want to check out http://tkcon.sourceforge.net, TkCon for a cross-platform console environment with lots of features.

Created by Jeff Hobbs on Thu, 21 Jun 2001 (MIT)
Tcl recipes (162)
Jeff Hobbs's recipes (16)

Required Modules

  • (none specified)

Other Information and Tasks