如何显示在正在运行的线程中创建的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 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()图将会显示出来。但是,如果我这样做
import threading
t = threading.Thread(target=run)
t.start()在执行do_something()期间,绘图没有响应,然后它被关闭。我要求一个解释,甚至更多的变通方法。
发布于 2014-05-28 05:09:48
首先,问题不是由chaco限制或引起的。它来自底层的gui工具包,正确地说是PyQt或wx。通过调用睡眠,您还可以禁止您的gui处理事件。一般来说,从不更改gui是一条主线。
https://stackoverflow.com/questions/23895588
复制相似问题