So, I'm digging through the code here and in every class (almost) I see an argument cnf={}
to the constructor, but unless I've missed it, it is not explicitly stated what cnf is / expected to contain. Can anyone clear this up? At first I thought it was for the keywords passed to tkinter widgets, but kw is appropriately for that. So, I'm confused about what role cnf={}
is playing.. as well as the extra=()
argument(s).
cnf must be a configuration dictionary mapping option names to values. It can be passed by position or by name (but not both!). This is very useful when several widgets have a common set of options. Options can also be passed (by keyword), and individual options override any in the dict. I verified these details with this experiment, run from IDLE. (If you run the below from a command line, add '-i' to the command line or root.mainloop() to the code.)
import tkinter as tk
root = tk.Tk()
d = {'bg': 'red'}
tk.Label(root, d).pack()
tk.Label(root, d, text='abc').pack()
tk.Label(root, cnf=d, text='abc').pack()
tk.Label(root, d, text='abc', bg='blue').pack()
tk.Label(root, d, cnf=d, text='abc').pack()
The result (stacked vertically) is a blank red label, 2 red 'abc' labels, a blue 'abc' label, and a TypeError in IDLE's Shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With