I'm working on a project using Python and Tkinter. I want to modularize it.
One of the main problems is that the implementation of my Toplevel
widget is too big.
I heard that it's possible to put this widget in a new class. The problem is I don't know how.
Here is how I define my main window:
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
Config(self)
So for my Toplevel
widget I tried:
class Config(tk.Toplevel):
def __init__(self, main):
tk.Toplevel.__init__(self)
Is it the right way to do this ?
Yes, that is the right way to do it. Though, you might want to keep a reference to the window so you can call methods on it later: