Web Analytics Made Easy - Statcounter
Skip to content

Matplotlib Window With GUI Window

There are 2 ways to use PySimpleGUI with Matplotlib. Both use the standard tkinter based Matplotlib.

The simplest is when both the interactive Matplotlib window and a PySimpleGUI window are running at the same time.

First the PySimpleGUI window appears giving you 3 options.


Clicking "Plot" will create the Matplotlib window


You can click the "Popup" button in the PySimpleGUI window and you'll see a popup window, proving the your GUI is still alive and operational.

import PySimpleGUI as sg
import matplotlib.pyplot as plt

    Simultaneous PySimpleGUI Window AND a Matplotlib Interactive Window
    A number of people have requested the ability to run a normal PySimpleGUI window that
    launches a MatplotLib window that is interactive with the usual Matplotlib controls.
    It turns out to be a rather simple thing to do.  The secret is to add parameter block=False to plt.show()

def draw_plot():
    plt.plot([0.1, 0.2, 0.5, 0.7])

layout = [[sg.Button('Plot'), sg.Cancel(), sg.Button('Popup')]]

window = sg.Window('Have some Matplotlib....', layout)

while True:
    event, values = window.read()
    if event in (sg.WIN_CLOSED, 'Cancel'):
    elif event == 'Plot':
    elif event == 'Popup':
        sg.popup('Yes, your application is still running')