之前一直在找如何用pysimplegui畫gui,然后在此基礎(chǔ)上畫上matplot的動(dòng)圖
先畫個(gè)window
window = sg.Window('autoTest', layout=layout, finalize=True)
再畫個(gè)canvas
layout = [[sg.Canvas(key='-TOOLBAR-')],
[sg.Canvas(key='-CANVAS-')]]
隨后把數(shù)據(jù)集畫上去
fig_canvas_agg = draw_figure(window['-CANVAS-'].TKCanvas, window['-TOOLBAR-'].TKCanvas, fig)
在此之前準(zhǔn)備數(shù)據(jù)
def make_figure(window):
plt.scatter(np.random.rand(1,10),np.random.rand(1,10))
window.write_event_value('-THREAD-', 'done.')
time.sleep(1)
return plt.gcf()
def draw_figure(canvas, canvas_toolbar, figure):
figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
figure_canvas_agg.draw()
toolbar = NavigationToolbar2Tk(figure_canvas_agg, canvas_toolbar)
toolbar.update()
figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
return figure_canvas_agg
fig = make_figure()
目前進(jìn)行到替換成自己的數(shù)據(jù),期望是動(dòng)態(tài)的
comming soon...