Book Image

wxPython Application Development Cookbook

By : Cody Precord
Book Image

wxPython Application Development Cookbook

By: Cody Precord

Overview of this book

wxPython is a GUI toolkit for the Python programming language built on top of the cross-platform wxWidgets GUI libraries. wxPython provides a powerful set of tools that allow you to quickly and efficiently building applications that can run on a variety of different platforms. Since wxWidgets provides a wrapper around each platform’s native GUI toolkit, the applications built with wxPython will have a native look and feel wherever they are deployed. This book will provide you with the skills to build highly functional and native looking user interfaces for Python applications on multiple operating system environments. By working through the recipes, you will gain insights into and exposure to creating applications using wxPython. With a wide range of topics covered in the book, there are recipes to get the most basic of beginners started in GUI programming as well as tips to help experienced users get more out of their applications. The recipes will take you from the most basic application constructs all the way through to the deployment of complete applications.
Table of Contents (17 chapters)
wxPython Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

In today's world of desktop applications, there is a great amount of incentive in being able to develop applications that can run in more than one environment. Currently, there are a handful of options available for cross platform frameworks to develop desktop applications in Python; wxPython is one such cross platform GUI toolkit for the Python programming language. It allows Python programmers to simply and easily create programs with a complete, highly functional graphical user interface. The wxPython code style has changed quite a bit over the years and has become much more Pythonic. The examples that you will find in this book are fully up to date and reflect this change in style. This cookbook provides you with the latest recipes to quickly create robust, reliable, and reusable wxPython applications. These recipes will guide you right from writing simple, basic wxPython scripts all the way through complex concepts and also feature various design approaches and techniques in wxPython.

This book starts off by covering a variety of topics, from the most basic requirements of a wxPython application to some of the more in-depth details of the inner workings of the framework, thus laying a foundation for any wxPython application. It then explains event handling, basic and advanced user interface controls, interface design and layout, creating dialogs, components, extending functionality, and so on. We will conclude by learning how to build and manage applications for distribution.

For each of the recipes, there is first an introductory and then more advanced examples along with plenty of example code that shows you how to develop and manage user-friendly applications. For more experienced developers, most recipes also include an additional discussion of the solution, allowing you to further customize and enhance the component.

What this book covers

Chapter 1, wxPython Starting Points, teaches the basics of getting started with building applications with wxPython.

Chapter 2, Common User Controls, introduces you to the commonly used UI components and how use them in wxPython.

Chapter 3, UI Layout and Organization, shows you how to lay out and present user controls on screen using Sizers.

Chapter 4, Containers and Advanced Controls, introduces you to various container-type and specialized controls, such as web browsers.

Chapter 5, Data Displays and Grids, shows you how to display and work with data using the Grids, Lists, and DataView controls.

Chapter 6, Ways to Notify and Alert, teaches you the techniques of alerting and notifying users with information.

Chapter 7, Requesting and Retrieving Information, shows you how to prompt users for information and input.

Chapter 8, User Interface Primitives, shows you how to use DeviceContexts to draw and customize your own UI components.

Chapter 9, Creating and Customizing Components, teaches you the techniques of designing and creating your own custom controls.

Chapter 10, Getting Your Application Ready for Release, shows you how to manage application configuration and build packages for release.

What you need for this book

All the recipes in this book were written using the following software:

  • wxPython 3.0.2.0

  • Python 2.7.9

A small selection of recipes requires some additional external Python packages, which are described in the recipe.

In addition to these tools, you will just need a good text editor that can work with Python files.

Who this book is for

This book is written for Python programmers wanting to develop user interfaces for their applications. An understanding of the Python language and basic object-oriented programming concepts is required to get the most out of this book.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To make the control visible to the user we call the Show method."

A block of code is set as follows:

class MyPanel(sized.SizedScrolledPanel):
    def __init__(self, parent):
        super(MyPanel, self).__init__(parent)

        self.SetSizerType("form")

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

class MyPanel(sized.SizedScrolledPanel):
    def __init__(self, parent):
        super(MyPanel, self).__init__(parent)

        self.SetSizerType("form")

Any command-line input or output is written as follows:

python main.py

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "So now, it's time to add this method in to build up a simple File and Edit menu."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.