Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4013874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:25:33+00:00 2026-05-20T09:25:33+00:00

I just encountered this strange situation: I found an example, where wx.Frame’s OnPaint is

  • 0

I just encountered this strange situation: I found an example, where wx.Frame’s OnPaint is overridden, and a circle is drawn. Funnily, as soon as I add even a single panel to the frame, the circle is not drawn anymore – in fact, OnPaint is not called at all anymore ! (Btw, I tried the example out on Ubuntu Lucid)

Can anyone explain me if this is the expected behavior, and how to correctly handle a wx.Frame’s OnPaint, if the wx.Frame has child panels ? Small code example is below..

Thanks in advance for any answers,
Cheers!

The code:

#!/usr/bin/env python

# http://www.linuxquestions.org/questions/programming-9/wxwidgets-wxpython-drawing-problems-with-onpaint-event-703946/

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title, size=wx.DefaultSize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, wx.DefaultPosition, size)

        self.circles = list()
        self.displaceX = 30
        self.displaceY = 30

        circlePos = (self.displaceX, self.displaceY)
        self.circles.append(circlePos)

        ## uncommenting either only first, or both of 
        ## the commands below, causes OnPaint *not* to be called anymore! 
        #~ self.panel = wx.Panel(self, wx.ID_ANY)
        #~ self.mpanelA = wx.Panel(self.panel, -1, size=(200,50))

        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, e):
        print "OnPaint called"
        dc = wx.PaintDC(self)
        dc.SetPen(wx.Pen(wx.BLUE))
        dc.SetBrush(wx.Brush(wx.BLUE))

        # Go through the list of circles to draw all of them
        for circle in self.circles:
            dc.DrawCircle(circle[0], circle[1], 10)


def main():
    app = wx.App()
    win = MainWindow(None, "Draw delayed circles", size=(620,460))
    win.Show()
    app.MainLoop()

if __name__ == "__main__":
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:25:34+00:00Added an answer on May 20, 2026 at 9:25 am

    OK, this isn’t really trivial, I guess… But I found the thread “wxPython – drawing without paint event – Python answers“, where it is mentioned:

    One nice strategy from an example in “wxPython in Action” is the
    following:

    • the frame has Draw methods that draw into a BufferedDC, which is
      chained to a bitmap member,
    • inside the paint method, the bitmap member is drawn to screen

    … however, that is actually slightly misleading – if we look at one of those examples, such as Chapter-06/example1.py, it is noticeable that the app spawns a wx.Frame (as in my example); but the wx.Frame here is simply initialized by instantiating a wx.Window – and it is here where all this DC onPaint stuff happens.

    With that in mind, my code above can be modified, so it finally works again (i.e. blue circle rendered), as below:

    #!/usr/bin/env python
    
    # http://www.linuxquestions.org/questions/programming-9/wxwidgets-wxpython-drawing-problems-with-onpaint-event-703946/
    
    import wx
    
    class MainWindowWindow(wx.Window):
        def __init__(self, parent):
            wx.Window.__init__(self, parent)
            self.Bind(wx.EVT_PAINT, self.OnPaint)
            self.circles = list()
            self.displaceX = 30
            self.displaceY = 30
    
            circlePos = (self.displaceX, self.displaceY)
            self.circles.append(circlePos)
    
            ## uncommenting either only first, or both of 
            ## the commands below, now calls onPaint
            ## (without these panels, OnPaint called once - with them, twice)
            self.panel = wx.Panel(self, wx.ID_ANY)
            self.mpanelA = wx.Panel(self.panel, -1, size=(200,50))
    
        def OnPaint(self, e):
            print "OnPaint called"
            dc = wx.PaintDC(self)
            dc.SetPen(wx.Pen(wx.BLUE))
            dc.SetBrush(wx.Brush(wx.BLUE))
    
            # Go through the list of circles to draw all of them
            for circle in self.circles:
                dc.DrawCircle(circle[0], circle[1], 10)
    
    
    class MainWindow(wx.Frame):
        def __init__(self, parent, title, size=wx.DefaultSize):
            wx.Frame.__init__(self, parent, wx.ID_ANY, title, wx.DefaultPosition, size)
            MainWindowWindow(self)
    
    
    def main():
        app = wx.App()
        win = MainWindow(None, "Draw delayed circles", size=(620,460))
        win.Show()
        app.MainLoop()
    
    if __name__ == "__main__":
        main()
    

    Well, hope this helps someone,
    Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just encountered this article of an extention of css sprites that enables the
I just encountered a strange behaviour with the GregorianCalendar class, and I was wondering
I’ve just encountered some strange behaviour when dealing with the ominous typographic apostrophe (
I've just encountered a rather strange problem. A Winforms (although that may not be
I encountered this page https://www.google.com/accounts/ServiceLogin , a Google service login page that (beyond just
I was just looking for a todolist service over the net. I encountered this
I just encountered the following situation. I have an Android app with a scenario
I've just encountered a strange mistake in a Silverlight project I'm working on with
I've encountered something very strange, and things just don't add up. First of all,
I've just encountered a weird problem, I'm trying to printf an integer variable, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.