Note that there are some explanatory texts on larger screens.

plurals
  1. POpanel repaints background image (using EVT_ERASE_BACKGROUND)
    primarykey
    data
    text
    <p>I have a frame with a few different panels and every panel shall get the same background image. So I found this example: <a href="http://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/" rel="nofollow">http://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/</a> 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: <a href="http://s14.directupload.net/file/d/3030/ej22mwbx_jpg.htm" rel="nofollow">http://s14.directupload.net/file/d/3030/ej22mwbx_jpg.htm</a> (the green bottom part is part of my image; the grey rectangle is my panel). I also added these lines to my __init__:</p> <pre><code>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() </code></pre> <p>But with these lines I can't start my program: No error message, but it just don't start.</p> <p>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.</p> <p>Edit2: I updated the code example above with all code that could be relevant.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload