【发布时间】:2017-03-17 04:27:43
【问题描述】:
我的 python 项目有多个线程正在运行。我想从 wxpython 库中添加一个仪表小部件来显示进度。我希望仪表充满直到我的第一个线程完成。我如何实现这一目标?我在 Windows 上使用 Python 2.7。
【问题讨论】:
标签: python-2.7 wxpython progress-bar wxwidgets python-multithreading
我的 python 项目有多个线程正在运行。我想从 wxpython 库中添加一个仪表小部件来显示进度。我希望仪表充满直到我的第一个线程完成。我如何实现这一目标?我在 Windows 上使用 Python 2.7。
【问题讨论】:
标签: python-2.7 wxpython progress-bar wxwidgets python-multithreading
使用 wx.CallAfter
def add_to_the_gauge(value):
your_gauge.Value += value
...
#in some thread
def some_thread_running():
wx.CallAfter(add_to_the_gauge, 2)
【讨论】:
您需要将工作线程中的事件发布到主线程,要求其更新仪表,请参阅this overview。
【讨论】:
你可以使用一些简单的东西 记得导入模块:
import os
然后把它放在框架上
def __init__(self, *a, **k):
filename = 'game.exe'
self.timer = wx.Timer()
self.Bind(wx.EVT_TIMER, self.OnUpdateGauge, self.timer)
self.timer.Start()
self.proc = os.popen(filename) # start the process
def OnUpdateGauge(self, event):
if self.proc.poll() == None: # return None if still running and 0 if stopped
self.timer.Stop()
return
else:
'''do something with the gauge'''
希望得到帮助
【讨论】: