Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
wxPython Application Development Cookbook

You're reading from   wxPython Application Development Cookbook Over 80 step-by-step recipes to get you up to speed with building your own wxPython applications

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785287732
Length 264 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Cody Precord Cody Precord
Author Profile Icon Cody Precord
Cody Precord
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. wxPython Starting Points FREE CHAPTER 2. Common User Controls 3. UI Layout and Organization 4. Containers and Advanced Controls 5. Data Displays and Grids 6. Ways to Notify and Alert 7. Requesting and Retrieving Information 8. User Interface Primitives 9. Creating and Customizing Components 10. Getting Your Application Ready for Release Index

Painting in your UI


All the controls that are visible on screen are created by being painted to DeviceContext. wxPython offers the EVT_PAINT event to allow user codes to paint their own custom displays on a canvas, such as a window, control, or panel. With this level of control on how the UI is painted, your imagination is the limit; however, in this recipe, we will start simple with just the basics of using EVT_PAINT and PaintDC. We will use these features to make a custom panel control that can use bitmaps as its background.

How to do it…

You need to perform the following steps:

  1. First, let's start by defining the custom Panel class that will use a bitmap for the background, as follows:

    class ImageBackground(wx.Panel):
        def __init__(self, parent, bitmap):
            super(ImageBackground, self).__init__(parent)
    
            self.bitmap = bitmap
            self.width = bitmap.Size.width
            self.height = bitmap.Size.height
    
            self.Bind(wx.EVT_PAINT, self.OnPaint)
  2. Next, we will define the OnPaint...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image