4

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 ?

Veedrac
  • 58,273
  • 15
  • 112
  • 169
user3703297
  • 75
  • 2
  • 6

1 Answers1

1

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:

self.config = Config(self)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685