I was trying to understand deeply the properties of the tkinter widgets, and for that I am calling the method configure
of the current widget object. There are some options of which I cannot understand their purpose.
For example, suppose I have a normal Entry
object, then I call the method configure
or config
to return the current properties, and the result is the following (I am using the function pprint
of the package called in the same way to print the result):
{'background': ('background',
'background',
'Background',
<border object: 'systemWindowBody'>,
'systemWindowBody'),
'bd': ('bd', '-borderwidth'),
'bg': ('bg', '-background'),
'borderwidth': ('borderwidth',
'borderWidth',
'BorderWidth',
<pixel object: '2'>,
2),
'cursor': ('cursor', 'cursor', 'Cursor', <cursor object: 'xterm'>, 'xterm'),
'disabledbackground': ('disabledbackground',
'disabledBackground',
'DisabledBackground',
<border object: 'systemWindowBody'>,
'systemWindowBody'),
'disabledforeground': ('disabledforeground',
'disabledForeground',
'DisabledForeground',
<color object: '#a3a3a3'>,
'#a3a3a3'),
'exportselection': ('exportselection',
'exportSelection',
'ExportSelection',
1,
1),
'fg': ('fg', '-foreground'),
'font': ('font', 'font', 'Font', <font object: 'TkTextFont'>, 'TkTextFont'),
'foreground': ('foreground',
'foreground',
'Foreground',
<color object: 'Black'>,
'Black'),
'highlightbackground': ('highlightbackground',
'highlightBackground',
'HighlightBackground',
<color object: 'systemWindowBody'>,
'systemWindowBody'),
'highlightcolor': ('highlightcolor',
'highlightColor',
'HighlightColor',
<color object: 'Black'>,
'Black'),
'highlightthickness': ('highlightthickness',
'highlightThickness',
'HighlightThickness',
<pixel object: '3'>,
3),
'insertbackground': ('insertbackground',
'insertBackground',
'Foreground',
<border object: 'Black'>,
'Black'),
'insertborderwidth': ('insertborderwidth',
'insertBorderWidth',
'BorderWidth',
<pixel object: '0'>,
0),
'insertofftime': ('insertofftime', 'insertOffTime', 'OffTime', 300, 300),
'insertontime': ('insertontime', 'insertOnTime', 'OnTime', 600, 600),
'insertwidth': ('insertwidth',
'insertWidth',
'InsertWidth',
<pixel object: '1'>,
1),
'invalidcommand': ('invalidcommand',
'invalidCommand',
'InvalidCommand',
'',
''),
'invcmd': ('invcmd', '-invalidcommand'),
'justify': ('justify', 'justify', 'Justify', <index object: 'left'>, 'left'),
'readonlybackground': ('readonlybackground',
'readonlyBackground',
'ReadonlyBackground',
<border object: 'systemWindowBody'>,
'systemWindowBody'),
'relief': ('relief', 'relief', 'Relief', <index object: 'sunken'>, 'sunken'),
'selectbackground': ('selectbackground',
'selectBackground',
'Foreground',
<border object: 'systemHighlight'>,
'systemHighlight'),
'selectborderwidth': ('selectborderwidth',
'selectBorderWidth',
'BorderWidth',
<pixel object: '1'>,
1),
'selectforeground': ('selectforeground',
'selectForeground',
'Background',
'',
''),
'show': ('show', 'show', 'Show', '', ''),
'state': ('state', 'state', 'State', <index object: 'normal'>, 'normal'),
'takefocus': ('takefocus', 'takeFocus', 'TakeFocus', '', ''),
'textvariable': ('textvariable', 'textVariable', 'Variable', '', ''),
'validate': ('validate',
'validate',
'Validate',
<index object: 'none'>,
'none'),
'validatecommand': ('validatecommand',
'validateCommand',
'ValidateCommand',
'',
''),
'vcmd': ('vcmd', '-validatecommand'),
'width': ('width', 'width', 'Width', 20, 20),
'xscrollcommand': ('xscrollcommand',
'xScrollCommand',
'ScrollCommand',
'',
'')}
Of course we cannot analyse each property and the corresponding tuple
, but I am asking you if there's a guide that explains exactly what each part of the tuple for each properties means.
If you want an example, we could start from the property background
. The tuple is the following:
('background',
'background',
'Background',
<border object: 'systemWindowBody'>,
'systemWindowBody')
systemWindowBody
is the value returned if I call the method cget
, in the following way:
print(entry.cget('bg'))
Now, what about the 3 first options? Why do we have a background written in uppercase and backgrounds written in lower case. I have thought: maybe we can use both, but actually we can just use the lower case version background
, otherwise we get the following error:
_tkinter.TclError: unknown option "-Background"
I would like also to know why there are 2 repeated lowercase options.
I have noticed that this pattern of elements in the tuples are also used in most of the properties, maybe all.
I am sorry for the long question, but I would really like to understand why this format.
See Question&Answers more detail:
os