Book Source Code
The book’s source code can be found on Github:
https://github.com/driscollis/wxPython_recipes_book_code
Table of Contents
Chapter 1: Introduction
Who Should Read This Book
About the Author
Conventions
Requirements
Book Source Code
Reader Feedback
Errata
Chapter 2: Working with Images
Recipe 2-1. How to Take a Screenshot of Your wxPython App
Problem
Solution
How It Works
The Snapshot Printer Script
Recipe 2-2. How to Embed an Image in the Title Bar
Problem
Solution
How It Works
Using Your Own Image
Create the Image in Python Code
Recipe 2-3. How to Put a Background Image on a Panel
Problem
A Bad Example
Solution
A Better Example
Chapter 3: Special Effects
Recipe 3-1. Resetting the Background Color
Problem
Solution
How It Works
Recipe 3-2. How to Create a “Dark Mode”
Problem
Solution
How It Works
Trying Out Dark Mode
Recipe 3-3. How to Fade-in a Frame/Dialog
Problem
Solution
How It Works
Recipe 3-4. Making Your Text Flash
Problem
Solution
How It Works
Creating Changing Text
Chapter 4: The Publish–Subscribe Pattern
Recipe 4-1. An Intro to Pubsub
Problem
Solution
How It Works
Recipe 4-2. Using PyDispatcher Instead of PubSub
Problem
Solution
How It Works
Chapter 5: Wizard Recipes
Recipe 5-1. Creating a Simple Wizard
Problem
Solution
How It Works
Using PyWizardPage
Recipe 5-2. How to Disable a Wizard’s Next Button
Problem
Solution
How It Works
Getting It to Work with wxPython 4/Phoenix
Recipe 5-3. How to Create a Generic Wizard
Problem
Solution
How It Works
Chapter 6: Creating Simple Widgets
Recipe 6-1. Creating an About Box
Problem
Solution
How It Works
Using HtmlWindow for an About Box
Updating the Code for wxPython 4/Phoenix
Recipe 6-2. Creating Graphs with PyPlot
Problem
Solution
How It Works
Graphing Using Saved Data
Point Plot with Thousands of Points
Creating a Sine/Cosine Graph
Recipe 6-3. Creating a Simple Notebook
Problem
Solution
How It Works
The Refactored Notebook
Chapter 7: Using Config Files
Recipe 7-1. Generating a Dialog from a Config File
Problem
Solution
How It Works
Recipe 7-2. Saving Data to a Config File
Problem
Solution
Creating a Controller
How It Works
Creating the View
Chapter 8: Working with Events
Recipe 8-1. Binding Multiple Widgets to the Same Handler
Problem
Solution
How It Works
Recipe 8-2. How to Fire Multiple Event Handlers
Problem
Solution
How It Works
Recipe 8-3. Get the Event Name Instead of an Integer
Problem
Solution
How It Works
Recipe 8-4. Catching Key and Char Events
Problem
Solution
How It Works
Catching Char Events
Recipe 8-5. Learning About Focus Events
Problem
Solution
How It Works
Losing Focus
Chapter 9: Drag and Drop
Recipe 9-1. How to Use Drag and Drop
Problem
Solution
Creating a FileDropTarget
How It Works
Creating a TextDropTarget
Custom DnD with PyDropTarget
Creating a Custom Drag-and-Drop App
Recipe 9-2. How to Drag and Drop a File from Your App to the OS
Problem
Solution
How It Works
Chapter 10: Working with Frames
Recipe 10-1. Using wx.Frame Styles
Problem
Solution(s)
How It Works
Create a Frame Without a Caption
Create a Frame with a Disabled Close Button
Create a Frame Without Maximize/Minimize
Create a Un-Resizable Frame
Create a Frame Without a System Menu
Create a Frame That Stays on Top
Recipe 10-2. Making Your Frame Maximize or Full Screen
Problem
Solution
How It Works
Making Your Application Full Screen
Recipe 10-3. Ensuring Only One Instance per Frame
Problem
Solution
Chapter 11: wxPython and the System Tray
Recipe 11-1. Creating Taskbar Icons
Problem
Solution
Creating the TaskBarIcon in Classic
How It Works
Creating the TaskBarIcon in wxPython 4
Recipe 11-2. Minimizing to the System Tray
Problem
Solution
How It Works
Making the Application Minimize to Tray
Chapter 12: Fun with Panels
Recipe 12-1. Making a Panel Self-Destruct
Problem
Solution
How It Works
Recipe 12-2. How to Switch Between Panels
Problem
Solution
How It Works
Chapter 13: Using Objects in Widgets
Recipe 13-1. Using ObjectListView Instead of ListCtrl
Problem
Solution
How It Works
Recipe 13-2. Storing Objects in ComboBox or ListBox
Problem
Solution
How It Works
Adding Objects to the wx.ComboBox
Chapter 14: XML and XRC
Recipe 14-1. Extracting XML from the RichTextCtrl
Problem
Solution
How It Works
Updating for wxPython 4
Recipe 14-2. An Introduction to XRC
Problem
Solution
How It Works
Creating a Notebook with XRC
Adding Controls Outside XRC
Recipe 14-3. An Introduction to XRCed
Problem
Solution
How It Works
Creating Something More Complex
Using XRCed to Generate Python Code
Recipe 14-4. How to Create a Grid in XRC
Problem
Solution
How It Works
Chapter 15: Working with Sizers
Recipe 15-1. How to Get Children Widgets from a Sizer
Problem
Solution
How It Works
Recipe 15-2. How to Center a Widget
Problem
Solution #1—Using Faux Spacers
How It Works
Solution #2—Using an AddStretchSpacer
How It Works
Solution #3—Centering Without Nested Sizers
Recipe 15-3. How to Make Widgets Wrap
Problem
Solution
How It Works
Recipe 15-4. Adding/Removing Widgets Dynamically
Problem
Solution
Chapter 16: Threads and Timers
Recipe 16-1. How to Update a Progress Bar from a Thread
Problem
Solution for wxPython 2.8.12 and Earlier
How It Works
Solution for wxPython 3 and Newer
How It Works
wx.PostEvent and Threads
Recipe 16-2. How to Update a Progress Bar from a Thread
Problem
Solution
Updating the Code for wxPython 3.0.2.0 and Newer
Recipe 16-3. A wx.Timer Tutorial
Problem
Solution
How It Works
Using Multiple Timers
Chapter 17: Redirecting Text
Recipe 17-1. Redirect Python’s Logging Module to a TextCtrl
Problem
Solution
How It Works
Recipe 17-2. Redirecting stdout/stderr
Problem
Solution—The Thread-Safe Method
How It Works
Solution—The Non-Thread-Safe Method
Recipe 17-3. How to Use the Clipboard
Problem
Solution
How It Works
Chapter 18: Grid Recipes
Recipe 18-1. Syncing Scrolling Between Two Grids
Problem
Solution
How It Works
Recipe 18-2. How to Get Selected Cells in a Grid
Problem
Solution
How It Works
Chapter 19: Working with Your Application
Recipe 19-1. How to Edit Your GUI Interactively Using reload( )
Problem
Solution
How It Works
Recipe 19-2. Updating Your Application with Esky
Problem
Solution
How It Works
Recipe 19-3. How to Create a Log-in Dialog
Problem
Solution
Using an Instance Variable
Chapter 20: Bonus Recipes
Recipe 20-1. Catching Exceptions from Anywhere
Problem
Solution
How It Works
Creating an Exception-Catching Decorator
Recipe 20-2. wxPython’s Context Managers
Problem
Solution
How It Works
Recipe 20-3. Converting wx.DateTime to Python datetime
Problem
Solution
How It Works
Recipe 20-4. Creating a URL Shortener
Problem
Solution
Shortening URLs with Other Shorteners
Index