1

这是我的代码的最小工作示例。

我正在尝试通过 gui 从用户那里获取一些输入,从而使用 matplotlib 绘制实时图。为了构建 gui,我使用了库easygui

但是,有一个问题:图表在从用户那里获取更新时停止构建,我希望它继续下去。有什么我在这里想念的吗。

#!/usr/bin/env python

from easygui import *
from matplotlib.pylab import *
import numpy
import random

n = 0
fig=plt.figure()
x=list()
y=list()
plt.title("live-plot generation")
plt.xlabel('Time(s)')
plt.ylabel('Power(mw)')
plt.ion()
plt.show()
calculated=[random.random() for a in range(40)]
recorded=[random.random() for a in range(40)]
possible=[random.random() for a in range(5)]

plt.axis([0,40,0,10000])
for a in range(0, len(recorded)):
        temp_y= recorded[a]
        x.append(a)
        y.append(temp_y)
        plt.scatter(a,temp_y)
        plt.draw()
        msg = "Change"
        title = "knob"
        choices = possible
        if a>9:
                b = (a/10) - numpy.fix(a/10)
                if b==0:
                        choice = choicebox(msg, title, choices)
                        print "change:", choice

这是easygui的下载链接

sudo python  setup.py  install

根据您的 linux 或操作系统版本。使用以下链接

4

1 回答 1

0

谢谢J.F. Sebastian

import easygui
from Tkinter    import Tk
from contextlib import contextmanager

@contextmanager
def tk(timeout=5):
    root = Tk() # default root
    root.withdraw() # remove from the screen

    # destroy all widgets in `timeout` seconds
    func_id = root.after(int(1000*timeout), root.quit)
    try:
        yield root
    finally: # cleanup
        root.after_cancel(func_id) # cancel callback
        root.destroy()

with tk(timeout=1.5):
        easygui.msgbox('message') # it blocks for at most `timeout` seconds
于 2013-09-11T12:42:16.167 回答