作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何显示在运行线程中创建的 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_something() 期间无响应,然后关闭。我要求一个解释,甚至更多的解决方法。
最佳答案
首先,问题不限于chaco,也不是由chaco引起的。它来自底层 gui 工具包,正确的 PyQt 或 wx。通过调用 sleep,您还可以禁止 gui 处理事件。作为一般规则,永远不要做 gui 更改是一个线程。
关于python - 在运行线程中显示 chaco 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23895588/
我是一名优秀的程序员,十分优秀!