Deacon_MENG
Deacon_MENG

Reputation: 9

wxpython infinite refresh panel cause program collapse

I met a problem when I try to use Wxpython + OpenCV to implement face detection.

Basically, my idea is design a GUI contains detected frames and two buttons. One is for start and the other is for stop. I use a panel as a container to display each frame, and infinitely refresh the panel within a very little time interval.

But when I run the program, If I click the start button, the program will collapse 2 second latter. And the stop button seems useless even before the program collapse.

I think it is the thread problem. Since the whole UI is a big loop, and If I need to refresh one of the component, say panel, all the time, I need to use different thread apart from the main thread.

Is that right? If yes, how should I do? If no, Please give me some extra hints.

thanks a million~! ;)

Upvotes: 0

Views: 194

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33071

You shouldn't refresh unless you have to. Refreshing needlessly is not the way to go. Only refresh when something changes. If you're using a thread to update a wxPython GUI component, then you need to be sure to use wxPython threadsafe methods, like wx.CallAfter, wx.CallLater or wx.PostEvent. See any of the following for more information on threads and wxPython:

Upvotes: 1

Related Questions