2

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?

4

1 回答 1

1

也许你可以遵循 MVC 设计模式(Model-View-Controller):

  • 您将应用程序逻辑保留在其类(模型)中。
  • 您将视图分为两部分:包含事件侦听器的控制器和包含小部件的视图。

对于带有 Swing 的 Java 应用程序,我已经这样做了。根据我对 Python 和 Tkinter 的适度经验,您可以在此处遵循 MVC 模式。

此链接可以启发您使用 Tkinter 的 MVC 示例

于 2013-05-03T16:27:32.450 回答