当用户单击具有新值和新范围的按钮时,我正在尝试更新Matplot图。我也在画布tkinter小部件内绘制该图。
我尝试将图形全局化,并用新值更新该图形,然后更新画布。
这是我的回调函数的代码:
def runAlgorithm(inputFileName,outputFileName,quantumTimeEntry,contextSwitchingTimeEntry,canvas):
global figurePlotter
if(not(contextSwitchingTimeEntry.isdigit()) or contextSwitchingTimeEntry==""):
messagebox.showinfo("Error","Please Enter a positive context switching time ")
return
if(inputFileName=="" or outputFileName==""):
return
if((not(quantumTimeEntry.isdigit()) or quantumTimeEntry=="" )and selectedAlgorithm=="RR"):
messagebox.showinfo("Error","Please Enter a positive quantum Time ")
return
contextSwitchTime=int(contextSwitchingTimeEntry)
if(selectedAlgorithm=="HPF"):
hpf=HPF(contextSwitchTime,inputFileName)
outputProcesses,detailedOutput=hpf.schedule()
if(selectedAlgorithm=="FCFS"):
fcfs=FCFS(contextSwitchTime)
fcfs.read_processes(inputFileName)
outputProcesses,detailedOutput=fcfs.schedule()
print("FCFS")
if(selectedAlgorithm=="SRTN"):
srtn=SRTN(contextSwitchTime,inputFileName)
outputProcesses,detailedOutput=srtn.schedule()
print("SRTN")
if(selectedAlgorithm=="RR"):
quantumTime=int(quantumTimeEntry)
roundrobin=RoundRobin(quantumTime,contextSwitchTime,inputFileName)
outputProcesses,detailedOutput=roundrobin.schedule()
print("RR")
#print (detailedOutput)
output2FileWriter=Output(outputFileName,outputProcesses)
output2FileWriter.writeOutput()
plotter = ProcessesPlotter()
plt.clf()
figurePlotter=plotter.plot(detailedOutput)
#print(figurePlotter)
#canvas.clear()
#canvas = FigureCanvasTkAgg(figurePlotter, master=rowFourFrame) # A tk.DrawingArea.
#canvas.draw()
#canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
canvas.get_tk_widget().update()