【发布时间】:2020-10-18 16:17:58
【问题描述】:
我创建了一个非常简单的 GUI,它有一个按钮和一个绘图。当我点击按钮时,我想在图中看到微调器,当它完成时,我只想看到新的情节。我尝试了一些东西,但不幸的是它不起作用......这是我的代码:
import threading
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
from pyqtspinner.spinner import WaitingSpinner
freqs = np.arange(2, 20, 3)
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2)
t = np.arange(0.0, 1.0, 0.001)
s = np.sin(2*np.pi*freqs[0]*t)
l, = plt.plot(t, s, lw=2)
class Index(object):
ind = 0
def next(self, event):
self.ind += 1
i = self.ind % len(freqs)
ydata = np.sin(2*np.pi*freqs[i]*t)
l.set_ydata(ydata)
plt.draw()
callback = Index()
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
bnext = Button(axnext, 'Next')
def process():
spin = WaitingSpinner(
fig,
roundness=70.0, opacity=15.0,
fade=70.0, radius=10.0, lines=12,
line_length=10.0, line_width=5.0,
speed=1.0, color=(0, 0, 0)
)
def the_proc():
time.sleep(10)
callback.next
def animated_loading(self):
spin.start()
the_process = threading.Thread(name='process', target=the_proc())
while the_process.isAlive():
animated_loading()
bnext.on_clicked(process)
plt.show()
【问题讨论】:
标签: python matplotlib pyqt