3.4 The Widget Hierarchy

masters and slaves

Widgets are arranged in a hierarchy. Each widget has a single parent. The only exceptions can be toplevel widget objects, which do not have to have a parent. The parent of a widget is given by the option parent in the tkInit message. Usually parent widgets are containers. To the parent of a widget we also refer to as its master. To the widget itself we refer to as slave of its master.

For example, in the previous example shown in Figure 3.2 the five frame widgets are slaves of the single toplevel widget.

The purpose of the hierarchy is threefold:

  1. The geometry for widgets is computed according to the hierarchy. This is discussed in Chapter 4.

  2. Creation and initialization has to follow the hierarchy. To initialize a widget object it is necessary that its parent widget object is already created and initialized. Otherwise initialization of a slave blocks until its master is initialized.

  3. Closing a parent widget object also closes all its slaves. The slaves are closed by applying them to the tkClose message. A widget object gets closed and its widget gets destroyed only after all of its slaves have been closed.

After a widget object has been closed, using it in tickles sent directly to the graphics engine, e. g. by Tk.send or Tk.batch, issues a runtime error.

Christian Schulte
Version 1.4.0 (20080702)