문제

How to properly set temporary text in statusbar, knowing that GUI operations need to take place in the main thread?

This is my current solution, using another thread

class StatusBar(wx.StatusBar):
    def __init__(self, parent):
        super(StatusBar, self).__init__(parent)

    def set_status(self, s, pause=None):
        if pause is None:
            self.SetStatusText(s)
        else:
            def aux():
                self.SetStatusText(s)
                time.sleep(pause)
                if self.GetStatusText() == s:
                    self.SetStatusText("")
            threading.Thread(target=aux).start()
도움이 되었습니까?

해결책

I would use a wx.Timer() object. You can set the timer to run for X number of milliseconds and then the event it is attached to will fire and you can clear the status bar's text and stop the timer too.

So you'd do something like this:

self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.clearStatus, self.timer)
self.timer.Start(10000)  # fire in 10 seconds

Then in your handler, you'd do something like this:

def clearStatus(self, event):
    self.SetStatusText("")
    self.timer.Stop()

You can read more at the following:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top