Question: There is a sample Python program that uses Python's tkinter and maplotlib packages to illustrate the workings of the model - view - controller pattern.
There is a sample Python program that uses Python's tkinter and maplotlib packages to illustrate the workings of the modelviewcontroller pattern.See if you can get this program running on your computer.Provide a short paragraph in comments in the source code explaining the relationship between each of the three pattern components.
import tkinter as Tk
from matplotlib.figure import Figure
from matplotlib.backends.backendtkagg import FigureCanvasTkAgg
import numpy as np
class Model:
def initself:
self.xpoint
self.ypoint
self.res None
def calculateself:
x y npmeshgridnplinspace self.xpoint
nplinspace self.ypoint
z npcosxy
self.res x: xy: yz: z
class View:
def initself master:
self.frame TkFramemaster
self.fig Figurefigsize dpi
self.ax self.fig.addaxes
facecolor frameonFalse
self.frame.packsideTkLEFT, fillTkBOTH, expand
self.sidepanel SidePanelmaster
self.canvas FigureCanvasTkAggselffig, masterself.frame
self.canvas.gettkwidgetpacksideTkTOP, fillTkBOTH, expand
self.canvas.draw
class SidePanel:
def initself root:
self.frame TkFrameroot
self.framepacksideTkLEFT, fillTkBOTH, expand
self.plotBut TkButtonselfframe text"Plot
self.plotBut.packside"top", fillTkBOTH
self.clearButton TkButtonselfframe text"Clear"
self.clearButton.packside"top", fillTkBOTH
class Controller:
def initself:
self.root TkTk
self.model Model
self.view Viewselfroot
self.view.sidepanel.plotBut.bind self.myplot
self.view.sidepanel.clearButton.bind self.clear
def runself:
self.root.titleTkinter MVC example"
self.root.deiconify
self.root.mainloop
def clearself event:
self.view.axclear
self.view.fig.canvas.draw
def myplotself event:
self.model.calculate
self.view.axclear
self.view.axcontourf
self.model.resx self.model.resy self.model.resz
self.view.fig.canvas.draw
if namemain:
c Controller
crun
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
