【问题标题】:PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebookPySimpleGUI matplotlib 图形未显示为弹出窗口,仅在笔记本中显示图形
【发布时间】:2020-10-14 20:56:28
【问题描述】:

我正在尝试运行此演示代码,并希望在我运行我的工具时出现图形的弹出窗口,并让用户可以选择横向单击下一个图形。目前,该图表仅在我的 jupyter 笔记本中的代码下绘制,而不是在我运行代码时作为弹出窗口绘制。我不确定为什么会这样?

我想要的示例:

matplotlib graph example

这里的演示程序代码:

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()

请有人让我知道我在这里做错了什么吗? 谢谢

【问题讨论】:

    标签: python python-3.x matplotlib pysimplegui


    【解决方案1】:

    它可能是您当前正在使用的 IDE,但是当我执行您的代码时,会弹出一个带有绘图的单独窗口。该代码似乎已经完成了您希望它执行的操作。

    【讨论】:

    • 谢谢!!我没有意识到会发生这种情况,当我将其转换为可执行文件时它运行良好。
    猜你喜欢
    • 2021-11-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    • 2017-12-25
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    相关资源
    最近更新 更多