How to do it...

After reverse-engineering the gui2py code and making other changes to this code, we may achieve the following window widget, which displays a nice, tiled background:

wxPython_Wallpaper_simple.py

Of course, we lost a lot of widgets refactoring the code from the aforementioned website, yet it does give us a cool background, and clicking the Quit button still works.

The next step is to figure out how to integrate the interesting part of the code into our own GUI. We do this by adding the following code to the GUI in the previous recipe:

#---------------------------------------------------------- 
class GUI(wx.Panel): # Subclass wxPython Panel
def __init__(self, parent):
wx.Panel.__init__(self, parent)

imageFile = 'Tile.bmp'
self.bmp = wx.Bitmap(imageFile)
# react to a resize event and redraw image
parent.Bind(wx.EVT_SIZE, self.canvasCallback)

def canvasCallback(self, event=None):
# create the device context
dc = wx.ClientDC(self)
brushBMP = wx.Brush(self.bmp)
dc.SetBrush(brushBMP)
width, height = self.GetClientSize()
dc.DrawRectangle(0, 0, width, height)
We have to bind to parent, not self; otherwise, our bitmap will not show up.

Running our improved code now tiles a bitmap as the background of our GUI:

wxPython_Wallpaper.py

Clicking the button still invokes our OpenGL 3D drawing, so we did not lose any functionality:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.71.28