Now I know there are two ways to do this:
1 class inheritance Dict classes defined
For example
Class A (dict): Pass
A = A ()
a[' name '] = 12
2 Adding a custom class
__setitem__ () __getitem__ () method
Class A:def __init__ (self, cfg={}): <strong><span style= "color: #ff0000;" >self.cfg = Cfg</span></strong>def __setitem__ (self, Key, value): <span style= "color: #ff0000;" >self.cfg[key] = Value</span>def __getitem__ (self, key): <span style= "color: #ff0000;" >return self.cfg[key]</span>a = A () a[' B '] = 2print (a[' B '])
Output:
2[finished in 0.0s]
This is to add a dictionary class object to the class and store the key,value in it.
In both of these ways, we can use ordinary objects just like dictionary class objects.
The second method is to learn tkinter when the use of this, in the Internet did not search methods, see its source code to find this method.
Python uses ordinary objects as dictionary classes (DICT)