我有一些简单的wxpython GUI,当我点击一个按钮点击时,我想在另一个线程中运行一些io任务(为了不阻止GUI)并在io线程运行时相应地更新GUI(例如,从io线程更新标签:“[io task percentage completed]%”)。
然而,有时它会起作用,有时会抛出异常:
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。
由于
答案 0 :(得分:-1)
这里有关于这个主题的大量线程,并且在wxpython wiki上有很好的介绍。查找wx.CallAfter。