听起来正在发生的事情是您的进程正忙于工作,因此它不会放弃任何周期让 GUI 刷新。
您需要做的是将繁忙的进程移到它自己的线程中。
你会想做类似的事情
import threading
class Encrypt(threading.Thread):
def __init__(self, threadNum, asset, window):
threading.Thread.__init__(self)
self.threadNum = threadNum
self.window = window
self.signal = True
def run(self):
while self.signal:
do_stuff_that_is_cpu_intensive
for self.path in self.paths: #etc..
在你的主要 wx.Frame 类中:
class Frame(wx.Frame):
def __init__(self, *args, **kwargs):
super(Frame, self).__init__(*args, **kwargs)
self.InitUI()
self.Show()
self.count = 0 # simple thread counter.
self.threads = [] # this lets you iterate over your threads if you ever need to
def OnEncrypt(self):
self.count += 1
thread = Encrypt(self.count, asset, self)
self.threads.append(thread)
thread.start()
在此处查看更详细的方法和解释:http: //www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/