-
Book Overview & Buying
-
Table Of Contents
wxPython Application Development Cookbook
By :
Bitmaps are the basic data type used to represent images in an application. The wx.Bitmap object can seamlessly load and decompress most common image file formats into a common representation that is usable by many UI controls. Adding bitmaps to the controls can make a UI more intuitive and easier to use.
Perform the following steps:
wx.Panel to use as the container for the control that will show our bitmap on the screen, as follows:class ImagePanel(wx.Panel):
def __init__(self, parent):
super(ImagePanel, self).__init__(parent)
# Load the image data into a Bitmap
theBitmap = wx.Bitmap("usingBitmaps.png")
# Create a control that can display the
# bitmap on the screen.
self.bitmap = wx.StaticBitmap(self, bitmap=theBitmap)class MyFrame(wx.Frame):
def __init__(self, parent, title=""):
super(MyFrame, self).__init__(parent, title=title)
# Set the panel
self.panel = ImagePanel(self)
The Bitmap class is used to load image data from the usingBitmaps.png file, which is located in the same directory as the script. This loads the PNG file data into a bitmap object, which can be used by the controls.
In this example, we used the StaticBitmap control, which is one of the easiest ways to display a bitmap in the UI. This control takes the bitmap data object and handles drawing it on the screen.
In this recipe, we used a PNG file as the source for the bitmap, but wx.Bitmap also supports a wide range of other image formats, such as BMP, GIF, ICO, ICON, JPEG, TIF, XBM, XPM, and several others, depending on the build of wxWidgets used by wxPython.
Change the font size
Change margin width
Change background colour