Next / Previous / Contents / TCC Help System / NM Tech homepage

27.4. Rules for resource matching

When you are creating a widget, and you don't specify a value for some option, and two or more resource specifications apply to that option, the most specific one applies.

For example, suppose your options file has these two lines:

*background: LimeGreen
*Listbox*background: FloralWhite

Both specifications apply to the background option in a Listbox widget, but the second one is more specific, so it will win.

In general, the names in a resource specification are a sequence n1, n2, n3, ..., o where each ni is a class or instance name. The class names are ordered from the highest to the lowest level, and o is the name of an option.

However, when Tkinter is creating a widget, all it has is the class name and the instance name of that widget.

Here are the precedence rules for resource specifications:

  1. The name of the option must match the o part of the option-pattern. For example, if the rule is

    xparrot*indicatoron: 0

    this will match only options named indicatoron.

  2. The tight-binding operator (.) is more specific than the loose-binding operator (*). For example, a line for *Button.font is more specific than a line for *Button*font.

  3. References to instances are more specific than references to classes. For example, if you have a button whose instance name is panicButton, a rule for *panicButton*font is more specific than a rule for *Button*font.

  4. A rule with more levels is more specific. For example, a rule for *Button*font is more specific than a rule for *font.

  5. If two rules have same number of levels, names earlier in the list are more specific than later names. For example, a rule for xparrot*font is more specific than a rule for *Button*font.