如何显示在运行线程中创建的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函数
run()
情节就会显现出来。但是如果我做了
import threading
t = threading.Thread(target=run)
t.start()
在执行do\u something()时,绘图没有响应,然后关闭。我要求一个解释,甚至更多的解决办法。你知道吗
首先,这个问题不受限制,也不是由查科造成的。它来自底层的gui工具箱,正确地说是PyQt或wx。通过调用sleep,还可以禁止gui处理事件。一般来说,从不做gui更改是一个线程。你知道吗
相关问题 更多 >
编程相关推荐