From 80febf4349ec8182cf54b5af992ba71d3d5f0ebb Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Thu, 21 Nov 2019 11:10:21 -0500 Subject: [PATCH] New demo! Using Matplotlib with PySimpleGUIQt (2 window solution) --- .../Qt_Demo_Matplotlib_Two_Windows.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 PySimpleGUIQt/Demo Programs/Qt_Demo_Matplotlib_Two_Windows.py diff --git a/PySimpleGUIQt/Demo Programs/Qt_Demo_Matplotlib_Two_Windows.py b/PySimpleGUIQt/Demo Programs/Qt_Demo_Matplotlib_Two_Windows.py new file mode 100644 index 00000000..15e5fe26 --- /dev/null +++ b/PySimpleGUIQt/Demo Programs/Qt_Demo_Matplotlib_Two_Windows.py @@ -0,0 +1,29 @@ +from matplotlib import use +# import PySimpleGUI as sg # Same program can be used with tkinter port +import PySimpleGUIQt as sg; use('qt5agg') +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]) + 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 (None, 'Cancel'): + break + elif event == 'Plot': + draw_plot() + elif event == 'Popup': + sg.popup('Yes, your application is still running') +window.close()