Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement the MVC-pattern in Tkinter

Tags:

I need a basic example where MVC pattern is used with Python TK. I have some code using Tkinter, however I would like to transform it using the MVC pattern.

like image 684
user618677 Avatar asked Oct 03 '11 16:10

user618677


People also ask

Can we use MVC in Python?

Python codeLet us consider a basic object called “Person” and create an MVC design pattern. It calls for a method, which fetches all the records of the Person table in database. The records are presented in JSON format.

What is MVC pattern in Python?

The MVC design pattern allows you to divide the application into three main components: model, view, and controller. This structure helps you focus on the logic of each part and make it more maintainable, especially when the application grows.

Can I use tkinter for app development?

There are loads of tutorials for starting of on Xcode or Android Studio which should help you get started. Show activity on this post. Tkinter is meant for desktop applications, not mobile apps. You won't be able to make a mobile app with Tkinter .

How does MVC work in Django?

DJANGO MVC - MVT Pattern The template is a HTML file mixed with Django Template Language (DTL). The developer provides the Model, the view and the template then just maps it to a URL and Django does the magic to serve it to the user.


2 Answers

I know this is quite old but I was able to find some decent examples using the MVC pattern with both Tk and wxPython, hopefully they provide some help for anyone stumbling upon this question.

wxPython: http://wiki.wxpython.org/ModelViewController

Tk: http://tkinter.unpythonic.net/wiki/ToyMVC This website no longer exists so I've hosted the code on a Gist here.

like image 186
ajfigueroa Avatar answered Sep 27 '22 22:09

ajfigueroa


Here's an interesting example: https://sukhbinder.wordpress.com/2014/12/25/an-example-of-model-view-controller-design-pattern-with-tkinter-python/

I would also recommend this book where the author goes through how to structure your Tkinter application in a model-view way: https://www.packtpub.com/application-development/tkinter-gui-application-development-hotshot

like image 24
Andreas Bergström Avatar answered Sep 27 '22 22:09

Andreas Bergström