0

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 ....."

2
  • Use self.Update() instead of self.Refresh() Refresh, updates during the next event loop iteration. However, there is a caveat: Use Refresh first if you want to immediately redraw the window unconditionally as Update doesn't do anything, if nothing requires redrawing. I Hope that's clear. (If in doubt try both) Commented Mar 6, 2021 at 16:24
  • Hey @RolfofSaxony thanks for your answer, yes, just before you answered I read about the update method. The solution to my problem is to first Refresh and then update....for anyone who still doesnt understand, please comment and Ill share my code. Commented Mar 6, 2021 at 16:42

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

After a day or two you will be able to Accept your own answer as correct. It may seem strange but the reasoning behind it, is that people looking for the answer to a similar question, tend to look at Accepted answers first. So this helps those struggling with a similar issue, find a solution. Welcome to StackOverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.