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

  • SEARCH
  • Home
  • 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 8637151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:24:25+00:00 2026-06-12T10:24:25+00:00

I have a frame with a few different panels and every panel shall get

  • 0

I have a frame with a few different panels and every panel shall get the same background image. So I found this example: http://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/
I copied the “def OnEraseBackground(self, evt)” from this example and Bind it to EVT_ERASE_BACKGROUND. Result: The panel repaints the background image with the colour grey. My background image has the same width, but it is higher than the panel. So here you can see that the panel repaints the image: http://s14.directupload.net/file/d/3030/ej22mwbx_jpg.htm (the green bottom part is part of my image; the grey rectangle is my panel).
I also added these lines to my __init__:

import wx

class MyForm(wx.Frame):
    def __init__(self):    
        wx.Frame.__init__(self, None, wx.ID_ANY, "Click Kick",size=(1124,750),pos=((wx.DisplaySize()[0]-1024)/2,10))
        self.startpanel = wx.Panel(self,size=(1024,600))
        self.hideallpanels()
        self.startpanel.Show()
        #...  
        wx.StaticText(self.startpanel,-1,'Testtext',pos=(120,220))
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        #self.sizer.Add(self.panelnewgame, 1, wx.EXPAND)
        #self.sizer.Add(self.panelloadgame, 1, wx.EXPAND)
        self.SetSizer(self.sizer)    
        #hSizer = wx.BoxSizer(wx.HORIZONTAL)
        #hSizer.Add((1,1), 1, wx.EXPAND)
        #hSizer.Add(self.sizer, 0, wx.TOP, 100)
        #hSizer.Add((1,1), 0, wx.ALL, 75)
        #self.SetSizer(hSizer)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    def hideallpanels(self):
        self.startpanel.Hide()
        #...

    def OnEraseBackground(self, evt):
        dc = evt.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        bmp = wx.Bitmap("background.bmp")
        dc.DrawBitmap(bmp, 0, 0)

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop()

But with these lines I can’t start my program: No error message, but it just don’t start.

Edit:
There is no need to resize the background image (or something else) when the window gets resized. the window is static and shouldn’t get resized.

Edit2: I updated the code example above with all code that could be relevant.

Edit3: Sorry, but now it runs. You just need a background image called “background.bmp” which should be bigger than the wx.Panel (or you lower the size of the wx.Panel) -> Just to see, that the panel repaints the image.

  • 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-06-12T10:24:27+00:00Added an answer on June 12, 2026 at 10:24 am

    The problem is a parenting issue. If you look at the rest of my tutorial you’ll notice that I’m binding the EVT_ERASE_BACKGROUND to the panel, NOT the frame. Also, the OnEraseBackground handler is updating the panel, not the frame, so you’ll need to change a couple of lines:

    class MyForm(wx.Frame):
        def __init__(self):
            ...
            # change the last line in the init
            self.startpanel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
    
        def OnEraseBackground(self, evt):
            dc = evt.GetDC()
            if not dc:
                dc = wx.ClientDC(self)
                # change this line too!!
                rect = self.startpanel.GetUpdateRegion().GetBox()
    

    You’ll probably want to use the frame’s SetSizeHints method to set the maximum and minimum resize limits though. Otherwise when you resize the frame larger than the image, you’ll see gray on the borders.

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

Sidebar

Related Questions

I have tried this a few different ways but none of them seem to
I have frame styles for the image: .frame { background:#efefef; border:1px solid #f6f6f6; box-shadow:
I have a few pages which I'd like to have the same background across,
I have a few UIButtons that I'd like to trigger short 5-10 frame animations
Within the frame of a chess applet, I have a few sets of such
I have a frame with 4 JPanels and 1 JScrollPane, the 4 panels are
I have come a across a few different methods for inserting data into SQL
I have a data.frame like this: (t=structure(list(count = c(NA, 2, NA, NA, NA, 8,
I've been struggling with this issue for a few hours. I have a table
I am a newbie user of Frama-C and have a few questions regarding assertions

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.