gpt4 book ai didi

python - 线程、wxpython 和状态栏

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:15 25 4
gpt4 key购买 nike

我正在做一个使用 wxStatusBar 的程序,当下载开始时,我会像这样启动一个子线程:

def OnDownload(self, event):
child = threading.Thread(target=self.Download)
child.setDaemon(True)
child.start()

下载是另一个没有参数的函数(self 除外)。我想从那里用一些关于下载进度的信息更新我的状态栏,但是当我尝试这样做时,我经常会遇到 Xwindow、glib 和 segfaults 错误。有解决这个问题的想法吗?

已解决:我只需要在线程内的 GUI 中更改某些内容之前包括 wx.MutexGuiEnter() 并在完成时包括 wx.MutexGuiLeave() 。例如

def Download(self):
#stuff that doesn't affect the GUI
wx.MutexGuiEnter()
self.SetStatusText("This is a thread")
wx.MutexGuiLeave()

就这些了:D

最佳答案

大多数人被引导到 wxPython wiki:

http://wiki.wxpython.org/LongRunningTasks

我在这里也写了一篇关于这个主题的小文章:

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

不过,我认为我以前从未见过您的解决方案。

关于python - 线程、wxpython 和状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4692726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com