I have been successfully creating and using tkinter custom classes using this initialization format:
class MyWidgetFrame(tk.Frame):
def __init__(self,master):
super().__init__()
But I came across a tutorial in which it was suggested that it is also necessary to pass the master (i.e. root or other container) to the parent:
class MyWidgetFrame(tk.Frame):
def __init__(self,master):
super().__init__(master)
My custom classes have been working fine without passing master in like this. But perhaps there is something I am not understanding. Is this a suggested practice?
CodePudding user response:
You may think it’s working fine, but it’s not working the way you think it is. If you have a class that inherits from a widget, you should pass the master every time.
When you don’t pass the master, every widget will be a child of the root window. For a very simple application it might not matter much, but for even moderately complex apps it will matter.