This is an unofficial mirror of Tkinter reference documentation (based on Python 2.7 and Tk 8.5) created by the late John Shipman.
It was last updated in 2013 and is unmaintained. [More info]
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:
The name of the option must match the
o
part of the
.
For example, if the rule is
option-pattern
xparrot*indicatoron: 0
this will match only options named indicatoron
.
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
.
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
.
A rule with more levels is more specific. For
example, a rule for *Button*font
is
more specific than a rule for *font
.
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
.