How To Embed Matplotlib In TKinter Window

In this Python TKinter article i want to show How To Embed Matplotlib In TKinter Window.

if you are interested in Python GUI Development, you can check the below links.

 

 

 

 

What Is Matplotlib ? 

Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety

of hardcopy formats and interactive environments across platforms. Matplotlib can be used in

Python scripts, the Python and IPython shells, the Jupyter notebook, web application servers,

and four graphical user interface toolkits.

 

 

 

Also you can read more articles on Python GUI Development

1: PyQt5 GUI Development Tutorials

2: Pyside2 GUI Development Tutorials

3: wxPython GUI Development Tutorials

4: Kivy GUI Development Tutorials 

 

 

 

 

 

 

So now this is the complete code for How To Embed Matplotlib In TKinter Window. make sure

that you have installed Matplotlib in your computer . if you have not installed, you can installed

by this command pip install matplotlib.

 

 

 

 

 

 

So at the top we have created our Root class that extends from TK, and we have added our window requirements like title, size and icon in the constructor of the class.

 

 

 

 

 

 

After that we have created our def matplotCanvas() method. in this method we have created our

Figure also we have created the values that we want to plot. the important point is this that you

need to created the object of FigureCanvasTKAgg().

 

 

 

 

 

This line of code is for creating NavigationToolbar for matplotlib window and we pass the object

of canvas in that.

 

 

 

 

 

Run the complete code and this will be the result.

How To Embed Matplotlib In TKinter Window
How To Embed Matplotlib In TKinter Window

 

 

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×