2019-12-24 23:52:47 +00:00
|
|
|
from matplotlib import use
|
2019-11-08 18:31:27 +00:00
|
|
|
import PySimpleGUI as sg
|
2019-12-24 23:52:47 +00:00
|
|
|
# import PySimpleGUIQt as sg; use('qt5agg')
|
2019-11-08 18:31:27 +00:00
|
|
|
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()
|
|
|
|
"""
|
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
def draw_plot():
|
|
|
|
plt.plot([0.1, 0.2, 0.5, 0.7])
|
|
|
|
plt.show(block=False)
|
2019-11-08 18:31:27 +00:00
|
|
|
|
|
|
|
layout = [[sg.Button('Plot'), sg.Cancel(), sg.Button('Popup')]]
|
2019-12-24 23:52:47 +00:00
|
|
|
|
2019-11-08 18:33:29 +00:00
|
|
|
window = sg.Window('Have some Matplotlib....', layout)
|
2019-11-08 18:31:27 +00:00
|
|
|
|
|
|
|
while True:
|
2019-11-08 18:33:29 +00:00
|
|
|
event, values = window.read()
|
2020-05-07 10:22:59 +00:00
|
|
|
if event in (sg.WIN_CLOSED, 'Cancel'):
|
2019-11-08 18:31:27 +00:00
|
|
|
break
|
|
|
|
elif event == 'Plot':
|
2019-12-24 23:52:47 +00:00
|
|
|
draw_plot()
|
2019-11-08 18:31:27 +00:00
|
|
|
elif event == 'Popup':
|
|
|
|
sg.popup('Yes, your application is still running')
|
2019-11-08 18:33:29 +00:00
|
|
|
window.close()
|