Reputation:
How can get a list of all config args?
from tkinter import *
from tkinter import ttk
root=Tk()
root.config(**args)
root.mainloop()
I tried with:
help(root.config)
The output:
Help on method configure in module tkinter:
configure(cnf=None, **kw) method of tkinter.Tk instance Configure resources of a widget.
The values for resources are specified as keyword arguments. To get an overview about the allowed keyword arguments call the method keys.
Upvotes: 1
Views: 459
Reputation:
Thank you @Axl for your answer .
from tkinter import *
from pprint import pprint
root=Tk()
pprint(root.key())
this code also works for me .
Upvotes: 0
Reputation: 15868
If by "config args" you mean all the configurable attributes of a particular widget, you can obtain them like this:
my_widget.config()
In other words, what you just need to do is calling the method config
(or configure
, which is simply an alias) without arguments, which returns a _dictionary with the attributes, their values and more of the widget.
You could also use the pprint
function (from the pprint
module) to print nicely the attributes, like in the following example:
from tkinter import *
from pprint import pprint
root = Tk()
pprint(root.config())
And the output is the following:
{'background': ('background',
'background',
'Background',
<border object: 'systemWindowBody'>,
'systemWindowBody'),
'bd': ('bd', '-borderwidth'),
'bg': ('bg', '-background'),
'borderwidth': ('borderwidth',
'borderWidth',
'BorderWidth',
<pixel object: '0'>,
0),
'class': ('class', 'class', 'Class', 'Toplevel', 'Tk'),
'colormap': ('colormap', 'colormap', 'Colormap', '', ''),
'container': ('container', 'container', 'Container', 0, 0),
'cursor': ('cursor', 'cursor', 'Cursor', '', ''),
'height': ('height', 'height', 'Height', <pixel object: '0'>, 0),
'highlightbackground': ('highlightbackground',
'highlightBackground',
'HighlightBackground',
<color object: 'systemWindowBody'>,
'systemWindowBody'),
'highlightcolor': ('highlightcolor',
'highlightColor',
'HighlightColor',
<color object: 'Black'>,
'Black'),
'highlightthickness': ('highlightthickness',
'highlightThickness',
'HighlightThickness',
<pixel object: '0'>,
0),
'menu': ('menu', 'menu', 'Menu', '', ''),
'padx': ('padx', 'padX', 'Pad', <pixel object: '0'>, <pixel object: '0'>),
'pady': ('pady', 'padY', 'Pad', <pixel object: '0'>, <pixel object: '0'>),
'relief': ('relief', 'relief', 'Relief', <index object: 'flat'>, 'flat'),
'screen': ('screen', 'screen', 'Screen', '', ''),
'takefocus': ('takefocus', 'takeFocus', 'TakeFocus', '0', '0'),
'use': ('use', 'use', 'Use', '', ''),
'visual': ('visual', 'visual', 'Visual', '', ''),
'width': ('width', 'width', 'Width', <pixel object: '0'>, 0)}
According to the documentation regarding the config
method at effbot.org:
config(cnf=None, **kw)
Modifies one or more widget options.
If called without an argument, this method returns a dictionary containing the current settings for all widget options. For each option key in the dictionary, the value is either a five-tuple
(option, option database key, option database class, default value, current value)
, or a two-tuple(option alias, option)
. The latter case is used for aliases likebg
(background
) andbd
(border width
).Note that the value fields aren’t correctly formatted for some option types. See the description of the keys method for more information, and a workaround.
Upvotes: 1