The Event Loop

An event loop is used to process window system events and other events like timers and network sockets. The different event types are described later. All Tk applications must have an event loop so that they function properly in the window system environment. Tk provides a standard event loop with the Tk_MainLoop procedure, which is called at the end of Tk_Main. The wish shell provides an event loop automatically. The tclsh shell does not, although you can add an event loop using pure Tcl as shown in Example 16-2 on page 220.

Some applications already have their own event loop. You have two choices if you want to add Tk to such an application. The first is to modify the existing event loop to call Tcl_DoOneEvent to process any ...

Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.