Chapter 49. Writing a Tk Widget in C

This chapter describes the implementation of a simple clock widget. Two implementations are shown: the original string-based command interface and the Tcl_Obj command interface.

A custom widget implemented in C has the advantage of being efficient and flexible. However, it requires more work, too. This chapter illustrates the effort by explaining the implementation of a clock widget. It is a digital clock that displays the current time according to a format string. This is something you could implement in several lines of Tcl using a label widget, the clock command, and after for periodic updates. However, the point of the example is to show the basic structure for a Tk widget implemented in C, not how much ...

Get Practical Programming in Tcl and Tk, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.