Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to put my graph in tkinter interface

from tkinter import * 
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, 
NavigationToolbar2Tk)
  
# plot function is created for 
# plotting the graph in 
# tkinter window
def plot():
  
    # the figure that will contain the plot
    fig = Figure(figsize = (5, 5),
                 dpi = 100)
  
    # list of squares
    y = [i**2 for i in range(101)]
  
    # adding the subplot
    plot1 = fig.add_subplot(111)
  
    # plotting the graph
    plot1.plot(y)
  
    # creating the Tkinter canvas
    # containing the Matplotlib figure
    canvas = FigureCanvasTkAgg(fig,
                               master = window)  
    canvas.draw()
  
    # placing the canvas on the Tkinter window
    canvas.get_tk_widget().pack()
  
    # creating the Matplotlib toolbar
    toolbar = NavigationToolbar2Tk(canvas,
                                   window)
    toolbar.update()
  
    # placing the toolbar on the Tkinter window
    canvas.get_tk_widget().pack()
  
# the main Tkinter window
window = Tk()
  
# setting the title 
window.title('Plotting in Tkinter')
  
# dimensions of the main window
window.geometry("500x500")
  
# button that displays the plot
plot_button = Button(master = window, 
                     command = plot,
                     height = 2, 
                     width = 10,
                     text = "Plot")
  
# place the button 
# in main window
plot_button.pack()
  
# run the gui
window.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: not equal to in python 
Python :: check if variable is defined in python 
Python :: python ip camera 
Python :: relu python 
Python :: python inspect 
Python :: how to import files from desktop to python 
Python :: python game github 
Python :: flask run development mode 
Python :: get_or_create in django 
Python :: python compare dates 
Python :: python get bits from byte 
Python :: is plaindrome python 
Python :: django group permissions method 
Python :: print with color python 
Python :: ipython play audio 
Python :: df iloc 
Python :: How to take n space separated Integer in a list in python? 
Python :: Django - Knox auth setup 
Python :: iloc pandas 
Python :: Multiple Function in python with input method 
Python :: jupyter read excel 
Python :: how to append a tuple to a list 
Python :: # Python string capitalization 
Python :: python collections to dictionary 
Python :: python with example 
Python :: python selenium console log 
Python :: save jupyter notebook session 
Python :: assert with message python 
Python :: upper python python.org 
Python :: how to make an array python 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =