如何显示在运行线程中创建的 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() 期间没有响应,然后关闭。我要求解释,甚至更多的解决方法。