import tkinter as tk from tkinter import * from tkinter import ttk import matplotlib.pyplot as plt from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk) cnt=1 class Experiment: def __init__(self, root): self.gui(root) def gui(self, root): self.bStart=Button(root,text="START",command=self.hello,font=('Arial','24')) self.bStart.pack() self.bStop=Button(root,text="STOP",command=exit,font=('Arial','24')) self.bStop.pack() self.fig=plt.figure() self.ax = self.fig.add_subplot(1,1,1) self.ax.set_xlim([0,20]) self.ax.set_ylim([0,20]) self.ax.plot([i for i in range(10)],[i for i in range(10)]) self.canvas = FigureCanvasTkAgg(self.fig, master = root) self.canvas.draw() # placing the canvas on the Tkinter window self.canvas.get_tk_widget().pack() # creating the Matplotlib toolbar self.toolbar = NavigationToolbar2Tk(self.canvas, root) self.toolbar.update() # placing the toolbar on the Tkinter window self.canvas.get_tk_widget().pack() def hello(self): global cnt cnt = cnt + 1 self.ax.plot([i for i in range(20)],[i/cnt for i in range(20)]) self.canvas.draw() print("Hello ") print(cnt) if __name__ == '__main__': cnt=1 root=Tk() Experiment(root) root.mainloop()