Chris Irwin
Chris Irwin

Reputation: 117

Organize tkinter application

I have a question about application programming using Python and tkinter.

All the simple examples I see in tutorials use one class for all the widgets and all the bound methods. I decided to do this from the start since I saw no other examples, not thinking anything about it. As my application has grown, I've got a lot of methods in this one class, and it's getting kind of ridiculous.

Luckily, I am designing a front end for an application that I had already made for the console, so the application logic itself is contained in another class, but I still have a lot of methods in my one front end class.

Is there some other way to do this I'm missing?

Upvotes: 2

Views: 421

Answers (1)

Hakim
Hakim

Reputation: 3437

Maybe you can follow the MVC design pattern (Model-View-Controller):

  • You keep your application logic in its class (Model).
  • You separate your view to two parts: a Controller which contains event listeners and the View which contains the widgets.

I have done it this way for a Java application with Swing. From my modest experience with Python & Tkinter you can follow the MVC patters here to.

This link can inspire you MVC example with Tkinter

Upvotes: 1

Related Questions