PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook

847 views Asked by At

I'm trying to run this demo code and wanted the popup of the graph to appear when I run my tool and give the user the option to click sideways onto the next graph. Currently the graph is only plotting under my code in my jupyter notebook and not as a popup when I run the code. I'm not sure why this is happening?

Example of what I want:

matplotlib graph example

Code from demo program here:

from matplotlib import use
import PySimpleGUI as sg
import matplotlib.pyplot as plt


def draw_plot():
    plt.plot([0.1, 0.2, 0.5, 0.7])
    plt.show(block=False)

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'):
        break
    elif event == 'Plot':
        draw_plot()
    elif event == 'Popup':
        sg.popup('Yes, your application is still running')
window.close()

Please could someone let me know what I am doing wrong here? Thanks

1

There are 1 answers

1
MacItaly On BEST ANSWER

It could be the IDE that you're currently using, but when I execute your code a separate window pops open with the plot. The code seems to already do what you're wanting it to do.