2

我有一些简单的 wxpython GUI,当我单击按钮时,我想在另一个线程中运行一些 io 任务(为了不阻塞 GUI)并在 io 线程运行时相应地更新 GUI(例如更新来自 io 线程的标签:“[io 任务完成百分比]%”)。

但是有时这可行,有时会引发异常:

The program 'python2.7' received an X Window System error.
This probably reflects a bug in the program.
The error was 'RenderBadPicture (invalid Picture parameter)'.
  (Details: serial 14127 error_code 163 request_code 149 minor_code 7)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

使用 --sync 命令运行程序会产生以下错误:

[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called

我已经读过,不允许从创建 GUI 的线程之外的另一个线程更新 GUI 线程,但如果是这种情况,如何完成这个简单的任务?从另一个线程更新 GUI。

谢谢

4

1 回答 1

-1

这里已经有很多关于这个主题的主题,并且在 wxpython wiki 上得到了很好的介绍。查找 wx.CallAfter。

于 2012-12-27T03:56:46.947 回答