Creating the bubble chart view

To integrate MatplotLib into a Tkinter application, there are several imports we need to make.

The first is matplotlib itself:

import matplotlib
matplotlib.use('TkAgg')

It may seem odd to run code in the import section, and your editor may even complain about it. But before we import anything else from matplotlib we need to tell it which backend it should use. In this case, we want the TkAgg backend, which is made to integrate into Tkinter.

Now we can make a few more imports from matplotlib:

from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (
    FigureCanvasTkAgg, NavigationToolbar2TkAgg)

The Figure class represents the basic drawing area on which matplotlib charts can be drawn. ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.