\$\begingroup\$
\$\endgroup\$
3
Just starting to get the idea of MVC with tkinter. I wrote this simple program and I'm looking for feedback. There are no errors, but I don't know if I set it up right or not.
import tkinter as tk
class Model():
def __init__(self):
self.list = ["email", "sms", 'voice']
class View(tk.Frame):
def __init__(self, parent, controller):
self.controller = controller
tk.Frame.__init__(self, parent, bg="yellow", bd=2,
relief=tk.RIDGE)
self.parent = parent
self.pack()
self.labelVariable=tk.StringVar()
self.output=tk.Label(self, textvariable=self.labelVariable,
bg="orange", fg="white")
self.output.pack()
self.hello = tk.Button(self, text="Show", command=
self.controller.hello_Button_Pressed, bd=2,
relief=tk.RIDGE)
self.hello.pack(side="left")
class Controller():
def __init__(self):
self.root = tk.Tk()
self.model = Model()
self.view = View(self.root, self)
self.root.title("MVC example")
self.root.geometry("250x350")
self.root.config(background="LightBlue4")
self.root.mainloop()
def hello_Button_Pressed(self):
self.view.labelVariable.set(self.model.list)
if __name__ == '__main__':
c = Controller()
-
\$\begingroup\$ Welcome to Code Review. Can you tell us more about what the code is supposed to do? Does the code have a purpose? I understand you want to learn about MVC, that's your goal. What's the goal of the code? \$\endgroup\$Mast– Mast2019年12月26日 08:57:10 +00:00Commented Dec 26, 2019 at 8:57
-
\$\begingroup\$ Hi @Mast, thanks for responding. This code is just to print the list onto the label. Nothing else. I could do this code without MVC, but to elevate my learning, i wanted to organize it with MVC. If this is correct, without much feedback, I will begin to rewrite most of my other programs into MVC, so any thoughts are welcomed. thanks again. \$\endgroup\$fishtang– fishtang2019年12月26日 09:19:29 +00:00Commented Dec 26, 2019 at 9:19
-
\$\begingroup\$ Please edit the question to add the purpose of the code there. In the comment it is not visible enough. \$\endgroup\$Roland Illig– Roland Illig2020年02月05日 01:09:38 +00:00Commented Feb 5, 2020 at 1:09
1 Answer 1
\$\begingroup\$
\$\endgroup\$
2
The code looks like it is set up fine for MVC. I'm not an expert but I have enogh experience to tell that it's fine.
-
\$\begingroup\$ thanks @Cruise Lickerman. it took me a while to understand the set up of MVC, and now I can start use it. \$\endgroup\$fishtang– fishtang2020年01月06日 20:04:58 +00:00Commented Jan 6, 2020 at 20:04
-
\$\begingroup\$ Yeah took me a while also \$\endgroup\$terrenana– terrenana2020年01月06日 21:39:15 +00:00Commented Jan 6, 2020 at 21:39
You must log in to answer this question.
lang-py