Reputation: 11
I binded the paint event with the paint method. When I refresh the panel (which is supposed to call the event handler), it waits until the code after the refresh is done and only then calls it. Does someone why and how I could solve this problem? The Output is
def paint(self, event):
print("here first")
try:
dc = wx.BufferedPaintDC(self)
dc.DrawBitmap(self.bmp, 0, 0)
print("time here2", time.time())
except:
pass
def NextFrame(self):
self.Refresh()
time.sleep(5)
print("hey")
output:
hey
here first
time here2 1615033876.9332623
As you can see, it first prints the hey (which is supposed to happen after the "here first" and "time here2 ....."
Upvotes: 0
Views: 66
Reputation: 11
self.Refresh() updates during the next event loop iteration as Rolf of Saxony stated.
Self Update() immediately re-draws the panel only if there is something to re-draw.
Therefore the solution is to first Refresh() the panel, and one line after to Update().
Be sure you have the paint event
bound to the correct event handler.
Here is the code:
def bind_paint(self):
self.Bind(wx.EVT_PAINT, self.paint)
def call_paint(self):
self.Refresh() #will turn on the paint event
self.Update() #will go to event handler now
Upvotes: 1