Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  How can I do terminal emulation in Tk?
 Courtesy of Don Libes (
   +  Tk has no built-in terminal widget.  There have been a few attempts at
making a terminal widget as a Tk extension but none of these implementations
have been maintained (i.e., are available for the current version of Tk).
This isn`t surprising since all of them had significant limitations and it`s
not clear that this was a sensible approach in the first place.
   +  Borrow an external terminal emulator.  In particular, you can use
TkSteal to control an xterm.  You can also control an xterm with
Expect (  With TkSteal, your xterm physically appears inside the Tk
application.  And you can send X events to the emulator just like the user.
In contrast, Expect gives you control of the backend of the emulator -
so you can make the terminal display what you want, rather than being
restricted to the output of some existing program.  Similarly, when the user
enters keystrokes, you can read them and decide if you want to handle them
or pass them on to another program.  If you want control of both the user
interface and the backend, you can use both TkSteal and Expect together.
   +  Emulate a terminal using a text widget.  You can do dumb terminal
emulation by using Expect`s `expect_before` command to match characters
and insert them into the widget.  Expect`s tkterm example performs smart
terminal emulation.  It`s capable of handling emacs, vi, or any
termcap/terminfo/curses-based program.  And since it`s done with a text
widget, you can manipulate the display simply by accessing the text widget.
Exploring_Expect covers
both dumb and smart terminal emulation in the Tk chapter.