Python 在运行线程中显示chaco绘图
如何显示在运行线程中创建的Chaco绘图?我想举个例子可以让我的想法更清楚一些: 看一下我的示例代码,它使用Chaco创建了一个绘图Python 在运行线程中显示chaco绘图,python,multithreading,plot,chaco,Python,Multithreading,Plot,Chaco,如何显示在运行线程中创建的Chaco绘图?我想举个例子可以让我的想法更清楚一些: 看一下我的示例代码,它使用Chaco创建了一个绘图 from traits.api import HasTraits, Instance from traitsui.api import View, Item from chaco.api import ArrayPlotData, Plot from enable.component_editor import ComponentEditor class Lin
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
from chaco.api import ArrayPlotData, Plot
from enable.component_editor import ComponentEditor
class LinePlot(HasTraits):
plot = Instance(Plot)
traits_view = View(
Item('plot', editor=ComponentEditor(),
show_label=False
),
kind='live'
)
def __init__(self):
super(LinePlot, self).__init__()
x = range(10)
plotdata = ArrayPlotData(x=x, y=x)
self.plot = Plot(plotdata)
self.plot.plot(('x','y'))
def run():
l = LinePlot()
l.edit_traits()
do_something()
def do_something():
import time;time.sleep(10)
如果我只是通过调用run函数
run()
情节会显示出来。但是如果我做了类似的事情
import threading
t = threading.Thread(target=run)
t.start()
在执行do_something()期间,绘图没有响应,然后关闭。我需要一个解释,甚至更多的是一个解决方法。首先,这个问题不是由chaco限制或引起的。它来自底层gui工具包,正确地说是PyQt或wx。通过调用sleep,还可以禁止gui处理事件。一般来说,永远不要更改gui是一个线程。好的,谢谢。对于GUI更改,您的意思是:除了更新绘图之外,什么都不做?因此,在线程启动之前,GUI必须设置并运行?您要做的是将阻塞内容放入线程中,例如计算或io。