小编Mik*_*ter的帖子

在没有while循环的情况下更新wx.gauge

几天来一直在想这个问题:

我有一个像这样的基本wxpython程序:

from MyModule import *

class Form(wx.Panel):
  def __init__(self, parent, id):
    self.gauge = wx.Gauge(...)
    ...
  def ButtonClick(self, event):
    proc = LongProcess()
    while (LongProcess):
      self.gauge.SetValue(LongProcess.status)
      wx.Yield()
Run Code Online (Sandbox Code Playgroud)

导入MyModule.py:

from threading import *

class LongProcess(self):
  def __init__(self):
    Thread.__init__(self)
    self.start()
  def run(self):
    for i in range(100):
      Do_something()
      self.status = i  
Run Code Online (Sandbox Code Playgroud)

这会根据预期的值LongProcess.status更新仪表.但是while循环似乎不合适,因为整个程序使用100%的cpu负载,因为它不断检查状态(这并不奇怪,因此).有没有办法将状态发送回"母程序",而不是每秒数百万次?

python wxpython

3
推荐指数
1
解决办法
3182
查看次数

标签 统计

python ×1

wxpython ×1