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
wxPython Application Development Cookbook
wxPython Application Development Cookbook

wxPython Application Development Cookbook: Over 80 step-by-step recipes to get you up to speed with building your own wxPython applications

eBook
Mex$179.99 Mex$803.99
Paperback
Mex$1004.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

wxPython Application Development Cookbook

Chapter 1. wxPython Starting Points

In this chapter, we will cover:

  • Creating an application object
  • Adding the main frame
  • Using bitmaps
  • Binding to events
  • Understanding the hierarchy of the UI
  • Controlling the propagation of events
  • Accessing the clipboard
  • Supporting drag and drop
  • Handling AppleEvents

Introduction

In this chapter, we will take a quick overview on getting started with wxPython, including how to get an app started as well as handling events and supporting basic integration with various operating system features for the environments that the application may be operated in. These concepts are used throughout the recipes in this book as well as in any wxPython application you may develop. The recipes throughout this book target wxPython 3.0 running on Python 2.7. Many features exist and work in earlier versions of wxPython as well, but your mileage may vary with the recipes in this book when using a version earlier than 3.0.

Creating an application object

The App object is an object that all wxPython applications must create before any other GUI object. This object creates the application and provides its main event loop, which is used to dispatch events and connect actions in the UI with the actions in your programs.

This recipe will introduce how to create a minimal wxPython application, which will be used as foundation for every other recipe in this book.

How to do it…

Perform the following steps:

  1. Make the script as follows:
    import wx
    
    class MyApp(wx.App):
        def OnInit(self):
            wx.MessageBox("Hello wxPython", "wxApp")
            return True
    
    if __name__ == "__main__":
        app = MyApp(False)
        app.MainLoop()
  2. Run the script and take a look at the result:
    How to do it…

How it works…

There are three things to take note of in this simple application: the first, we created a subclass of the wx.App object; the second, we overrode the OnInit method; and the third, we called the MainLoop method of the application object. These simple steps set up the base for any application.

The OnInit method is called by the application's MainLoop method when it is started and provides an entry point to start up the main logic and user interface of your application. In this example, we just used it to show a simple pop-up dialog box. The application's MainLoop method continues to run until the last window associated with the application is closed. The OnInit method must return true in order to continue the initialization of the MainLoop applications.

The MainLoop method processes and dispatches all the messages that are needed to present the UI and direct messages for user actions initiated with button clicks. When the OK button is clicked on the dialog, it sends a message that is dispatched by the MainLoop method to close the dialog. In this example, once the dialog has returned, OnInit will also return, and there will be no window objects remaining. So, the application's MainLoop method will return as well, and this script will exit.

There's more…

Though generally the wx.App object is created as we did in this example, the class constructor also has four optional keyword arguments that can be used to modify some of its behavior:

  wx.App(redirect=False, filename=None, useBestVisual=False, clearSigInt=True)

The four optional keyword arguments are as follows:

  • redirect: If set to True, stdout is redirected to a debug window
  • filename: If redirect is True and this is not None, then stdout can be redirected to a file specified by this argument
  • useBestVisual: This specifies whether the application should try to use the best visuals provided by the underlying toolkit. (This has no effect on most systems.)
  • clearSigInt: Setting this to True will allow the application to be terminated by pressing Ctrl+C from the command line.

See also

  • The Handling errors gracefully recipe in Chapter 10, Getting Your Application Ready for Release, provides additional information on methods that can be overridden in wx.App.

Adding the main frame

Most applications have some sort of main window that they want to show to allow their users to interact with the software. In wxPython, this window is called a frame. The frame is the main top-level container and the base for building most user interfaces in wxPython. This recipe will show how to create a frame and add it to an application.

How to do it…

You can do this by performing the following steps:

  1. Start by making a subclass of wx.Frame with the following code:
    class MyFrame(wx.Frame):
        def __init__(self, parent, title=""):
            super(MyFrame, self).__init__(parent, title=title)
            
            # Set an application icon
            self.SetIcon(wx.Icon("appIcon.png"))
            
            # Set the panel
            self.panel = wx.Panel(self)
  2. Next, create an instance of the frame and show it using the following code:
    class MyApp(wx.App):
        def OnInit(self):
            self.frame = MyFrame(None, title="Main Frame")
            self.frame.Show()
            return True
  3. Run the script and take a look at what we made:
    How to do it…

How it works…

The Frame class creates a top-level window that can be used to present any number of other controls. A frame can be created without any parent window and will remain in the application until it is dismissed by the user.

In this recipe, we set up a couple of items on the MyFrame class:

  1. We called SetIcon to set the custom application icon on the title bar of the frame. This icon was created from the appIcon.png file, which exists in the same directory as the script.
  2. We created a Panel object and set the frame as its parent object. A panel is a plain rectangular control used to contain other controls and is shown as the rectangular area inside the frame's borders. A panel must have a parent window in order to be created.

Finally, in the App object's OnInit method, we created an instance of the frame specifying the title that we wanted to show in the frame's title bar and then called its Show method to display it on the screen. This recipe can be used as the preparation to create any wxPython application.

There's more…

The wx.Frame constructor has several style flags that can be specified in its constructor to modify its behavior and appearance.

Style flag

Description

wx.DEFAULT_FRAME_STYLE

This flag is a bit mask of all the other flags described in the following sections

wx.MINIMIZE_BOX

This displays the minimize button on the title bar

wx.MAXIMIZE_BOX

This displays the maximize button on the title bar

wx.RESIZE_BORDER

This allows the frame to be resized by the user

wx.CAPTION

This displays a title caption on the frames title bar

wx.CLOSE_BOX

This displays the close button on the title bar

wx.SYSTEM_MENU

This displays a system menu (the menu that appears when clicking on the frame icon on Windows)

wx.CLIP_CHILDREN

This eliminates the flicker caused by background repainting (Windows only)

These style flags can be passed in any combination using a bitwise operator to turn off any of the features that you may not want to provide on all frames. Multiple flags can be combined using a bitwise or operation.

Using bitmaps

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.

How to do it…

Perform the following steps:

  1. Let's start this time by making a subclass of 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)
  2. Next, we will create an instance of the panel in a frame:
    class MyFrame(wx.Frame):
        def __init__(self, parent, title=""):
            super(MyFrame, self).__init__(parent, title=title)
            
            # Set the panel
            self.panel = ImagePanel(self)
  3. Run it and see the image shown on the panel:
    How to do it…

How it works…

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.

There's more…

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.

Binding to events

wxPython is an event-driven framework; this means that all actions and the running of the UI is driven by events. Events are fired by objects to indicate that something has happened or needs to happen. MainLoop then dispatches these events to callback methods that are registered to be notified of the event. This recipe will show how to bind callback functions to events.

How to do it…

Perform the following functions:

  1. First, start by creating a frame and binding to some of its events with the following code:
    class MyApp(wx.App):
        def OnInit(self):
            self.frame = wx.Frame(None, title="Binding Events")
            
            # Bind to events we are interested in
            self.frame.Bind(wx.EVT_SHOW, self.OnFrameShow)
            self.frame.Bind(wx.EVT_CLOSE, self.OnFrameExit)
            
            # Show the frame
            self.frame.Show()
            return True
  2. Next, define the event handler callback methods we specified in the Bind calls. These will get executed when the bound event occurs, as follows:
        def OnFrameShow(self, event):
            theFrame = event.EventObject
            print("Frame (%s) Shown!" % theFrame.Title)
            event.Skip()
    
        def OnFrameExit(self, event):
            theFrame = event.EventObject
            print("Frame (%s) is closing!" % theFrame.Title)
            event.Skip()

How it works…

In the OnInit method, we created a frame object and then called Bind on it two times in order to bind our own two callback methods to these events that the frame emits. In this case, we bound to EVT_SHOW and EVT_CLOSE; these two events will be emitted by a window when the window transitions from being hidden to shown on screen and then when it is closed. Binding to events allows us to add some application-specific response when these two events occur. Now, our app's OnFrameShow and OnFrameExit callbacks will be executed by the framework in response to the event and allow us to print our log messages.

The first event, EVT_SHOW, happens as part of when the Show method is called on the frame in the app's OnInit method. The other event, EVT_CLOSE, occurs when the frame's close button is clicked on.

The event handler methods used in Bind always take one argument, which is an event object. This object is passed into the handler by the framework when it is called. The event object contains information about the event, such as a reference to the object that emitted it and other state information depending on what type of event was emitted.

There's more…

The Bind function can also take some additional optional parameters to set more fine-grain control on when the callback should be executed, as follows:

Bind(event, handler, source=None, id=-1, id2=-1)

The arguments to this function are described as follows:

  • event: This is the event to bind to.
  • handler: This is the event handler callback function to bind.
  • source: This can be used to specify the window object that is the source of the event. If specified, then only when the source object generates the event will the handler be executed. By default, any event of the type that gets to the control will cause the handler to execute.
  • id1: This is used to specify the source object's ID instead of using the instance.
  • id2: When specified with id1, this can be used to specify a range of IDs to bind to.

There are many kinds of events that can be bound to depending on the type of control. The wxPython and wxWidgets online documentation provides a fairly complete list of events that are available for each control in the library. Note that the documentation is based on object hierarchy, so you may have to look to the base classes of an object to find the more general events that many controls share. You can find the documentation at http://wxpython.org/onlinedocs.php.

See also

  • Take a look at the Controlling the propagation of events recipe section in this chapter for information on the behavior of events.

Understanding the hierarchy of the UI

There are certain rules and requirements to create a user interface; in its most fundamental form, the UI is just a collection of rectangles contained within other rectangles. This recipe will discuss how the hierarchy of controls is linked together.

How to do it…

You need to perform the following steps:

  1. Let's start by defining the top-level window that resides at the top of the hierarchy:
    class MyFrame(wx.Frame):
        def __init__(self, parent, title=""):
            super(MyFrame, self).__init__(parent, title=title)
            
            self.panel = MyPanel(self)
  2. Next, let's define the Panel class, which will serve as the general container for user controls and give it a child control through the following code:
    class MyPanel(wx.Panel):
        def __init__(self, parent):
            super(MyPanel, self).__init__(parent)
            
            self.button = wx.Button(self, label="Push Me")

How it works…

All controls have an argument for a parent in their constructor. The parent is the container that the child control belongs to; so, in the first snippet when the MyPanel object was created, it was passed into the Frame object as its parent. This caused the panel rectangle to be placed inside of the rectangle of the Frame object. Then again, inside of the MyPanel object, a Button object was created with Panel as the parent, which instructed the button rectangle to be positioned inside the area owned by Panel.

There are three layers of containment in the window hierarchy for different categories of control types:

  • Top-level Windows (Frames and Dialogs): These cannot be contained by any type of container when displayed on screen. They are always at the top of the visual hierarchy.
  • General Containers (Panels, Notebooks, and so on): These are general container windows that serve the purpose of grouping other controls together and providing layout. They can contain other general containers or controls.
  • Controls (Buttons, CheckBoxes, ComboBoxes, and so on): These are user controls that cannot contain any other controls. They are the leaves at the bottom of the tree.

There's more…

When building an application with a user interface, this hierarchy is important to remember as it plays a critical role in how the layout and design of the interface is performed. Most notably, in the middle general containers layer, the nesting and composition of the control layout in combination with event handling can lead to unexpected issues if this hierarchy is forgotten. So, just remember this tree structure when building out your application's interface:

There's more…

See also

  • The Controlling the propagation of events recipe in this chapter explains the way this hierarchy affects how events are reported.

Controlling the propagation of events

There are two main types of events in wxPython:

  • Normal events
  • Command events

Understanding how these events travel through the framework is important to understanding how to develop an application in this event-driven framework. This recipe will develop an example to show how to control the way an event is propagated.

How to do it…

The following steps can help us:

  1. Let's start by creating a panel that has two buttons in it, by creating the following class:
    class MyPanel(wx.Panel):
        def __init__(self, parent):
            super(MyPanel, self).__init__(parent)
            
            sizer = wx.BoxSizer()
            self.button1 = wx.Button(self, label="Button 1")
            sizer.Add(self.button1)
            self.button2 = wx.Button(self, label="Button 2")
            sizer.Add(self.button2)
            self.SetSizer(sizer)
            
            self.Bind(wx.EVT_BUTTON, self.OnButton)
  2. Next, let's define the event handler for the panel to handle the button events as follows:
        def OnButton(self, event):
            button = event.EventObject
            print("Button (%s) event at Panel!" % button.Label)
            if button is self.button1:
                event.Skip()
  3. In the next layer, let's make a frame to hold the panel and also set it up to catch button events through the following code:
    class MyFrame(wx.Frame):
        def __init__(self, parent, title=""):
            super(MyFrame, self).__init__(parent, title=title)
            
            self.panel = MyPanel(self)
            
            self.Bind(wx.EVT_BUTTON, self.OnButton)
    
        def OnButton(self, event):
            button = event.EventObject
            print("Button (%s) event at Frame!" % button.Label)
            event.Skip()
  4. Finally, let's do the same thing at the app level:
    class MyApp(wx.App):
        def OnInit(self):
            self.frame = MyFrame(None, title="Event Propagation")
            self.frame.Show();
            
            self.Bind(wx.EVT_BUTTON, self.OnButton)
            return True
    
        def OnButton(self, event):
            button = event.EventObject
            print("Button (%s) event at App!" % button.Label)
            event.Skip()

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. 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.

How it works…

When you run this application and click on each of the buttons, you should see two distinct differences in behavior between how the events propagate. When clicking on the first button, the event handlers from the panel to the frame and finally to the app will be executed, whereas when clicking the second button, only the event handler at the panel is executed.

The EVT_BUTTON object is a command event, meaning it will propagate upward until it is stopped or it reaches the app. In this example, the second button is only propagated to the Panel handler because we called event.Skip when the event originated from the first button. Calling the Skip method tells the framework to propagate the event to the next handler in the chain, whereas not calling the Skip method tells the framework that the event has been handled and does not require further processing. So, it's important to know when to call Skip and when not to as sometimes it is necessary for the event to propagate to the base default handler in order for additional processing to occur. Try going back to the Binding to events recipe and removing the call to Skip in OnFrameExit to ensure that it prevents the frame from closing.

There's more…

As discussed at the beginning of this recipe, there are two types of events. This recipe only explored the more common types of command events that were propagated. Normal events stay local to where they are generated and do not propagate.

You can also create your own custom events if you want to use the event loop to pass messages using the newevent module in wx.lib, as follows:

import wx
import wx.lib.newevent

# Create a special event
MyEvent, EVT_MYEVENT = wx.lib.newevent.NewCommandEvent();

This creates a new event object type and event binder object. The EVT_MYEVENT binder object can be bound to as any other event. Then, the MyEvent event object can be emitted through the use of the wx.PostEvent function, which sends the instance of the event through the event handler chain.

Accessing the clipboard

The clipboard is a system resource used to pass user data between applications in the operating system. This is most often associated with copying and pasting actions in an application. This recipe will show some basics on putting and getting data from the clipboard.

How to do it…

  1. Let's first define a helper function to get some text from the clipboard, as follows:
    def GetClipboardText():
        text_obj = wx.TextDataObject()
        rtext = ""
        if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():
      if wx.TheClipboard.GetData(text_obj):
        rtext = text_obj.GetText()
        wx.TheClipboard.Close()
        return rtext
  2. Now, let's do the reverse and define a helper function to put text into the clipboard, as done with the following code:
    def SetClipboardText(text):
        data_o = wx.TextDataObject()
        data_o.SetText(text)
        if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():
            wx.TheClipboard.SetData(data_o)
            wx.TheClipboard.Close()

How it works…

Both functions work by creating TextDataObject, which provides a platform-independent way to represent the systems' native data format. Then, TheClipboard object is opened, and it is used to either get data from the clipboard of the given type or put data in the clipboard from the application. This can be boiled down to a simple three step process for any clipboard interaction:

  1. Open clipboard
  2. Set or get DataObject
  3. Close the clipboard

Closing the clipboard after using is very important; it may prevent other processes from accessing it. The clipboard should only be kept open momentarily.

There's more…

The clipboard supports many other datatypes besides plain text, which can be used based on the situation and needs of the application.

Datatypes

Description

wx.BitmapDataObject

This is a bitmap data from the clipboard (drag and drop)

wx.CustomDataObject

This is a base class to represent application-specific data

wx.DataObjectSimple

This is a base class to create other data object types

wx.DataObjectComposite

This is a base class to support multiple formats

wx.FileDataObject

This is the data object for filenames

wx.HTMLDataObject

This is the HTML-formatted text container

wx.URLDataObject

This is the URL container data object

See also

  • Take a look at the next recipe in this chapter, Supporting drag and drop, for more on how clipboard data objects can be used to transfer data between controls.

Supporting drag and drop

Many applications allow users to open files by dragging a file from the operating system and dropping it in the application. wxPython, of course, provides support for this as well, through its controls using DropTargets. This recipe will show how to set up a DropTarget to allow handling the dragging and dropping of files in an application.

How to do it…

  1. First, let's create a drop target object to accept files that are dragged over and dropped in the application with the following code:
    class MyFileDropTarget(wx.FileDropTarget):
        def __init__(self, target):
            super(MyFileDropTarget, self).__init__()
            self.target = target
    
        def OnDropFiles(self, x, y, filenames):
            for fname in filenames:
                self.target.AppendText(fname)
  2. Next, all that is left is to connect the drop target to the window that should accept the dropped file(s). An example of this is shown in the following code:
    class MyFrame(wx.Frame):
        def __init__(self, parent, title=""):
            super(MyFrame, self).__init__(parent, title=title)
            
            # Set the panel
            self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE)
            self.text.AppendText("Drag and drop some files here!")
            dropTarget = MyFileDropTarget(self.text)
            self.text.SetDropTarget(dropTarget)

How it works…

Drag and drop functions with the use of DropSources and DropTargets. In this case, we wanted to allow files to be dropped in the application, so FileDropTarget was created and associated with the TextCtrl window. DropTargets have several virtual callback functions that can be overridden to intercept different actions during the drag and drop events. As FileDropTarget is specialized for files, it only required overriding OnDropFiles, which is called with the list of filenames that were dropped in the application. It is necessary to subclass the drop target in order to intercept and handle the data it receives.

In order for a window to accept drag and drop actions, it must have a DropTarget set; the DropTarget then gives feedback on whether the data can be accepted or not as well as handling the reception of the data. Try out the example code with this recipe and you will see the mouse cursor change as you drag a file over; then, try again by dragging some text from another application to see the difference.

There's more…

It's also possible to create more application-specific drag and drop handling if needed for custom datatypes by deriving a custom drop target class from PyDropTarget. This class provides several more overridable methods to allow the handling of various events during the action. Here's a table explaining this:

Methods

Description

OnEnter(x, y, dragResult)

This is called when a drag object enters the window. The dragResult value returned from this method sets the custom cursor to provide feedback to the user (wx.DragCancel, wx.DragCopy, and so on).

OnDragOver(x, y, dragResult)

This is called while the object is dragged over the window. It returns a dragResult to give visual feedback.

OnLeave()

This is called when the drag object leaves the window.

OnDrop(x, y)

This is called when the drag object is dropped in the window. This method should return True if the data is accepted.

OnData(x, y, dragResult)

This is called after the data is accepted in OnDrop. The dropped data object is contained in drop targets data object (refer to GetDataObject). This should then typically just return the default passed in dragResult.

Handling AppleEvents

AppleEvents are special kinds of high-level system events used by the OS X operating system to pass information between processes. In order to handle system events, such as when a file is dropped in the application's Dock icon, it's necessary to handle AppleEvents. Implementing the handlers for these methods can allow your app to behave more natively when run on OS X.

Note

This recipe is specific to the OS X operating system and will have no effect on other operating systems.

How to do it…

Perform the following steps:

  1. Define an app object in which we will override the available AppleEvent handlers through the following code:
    class MyApp(wx.App):
        def OnInit(self):
            self.frame = MyFrame("Apple Events")
            self.frame.Show()
            return True
  2. Override the handlers that are available to deal with the opening of files:
        def MacNewFile(self):
            """Called in response to an open-application event"""
            self.frame.AddNewFile()
    
        def MacOpenFiles(self, fileNames):
            """Called in response to an openFiles message in Cocoa
            or an open-document event in Carbon
            """
            self.frame.AddFiles(fileNames)
  3. Finally, let's also override the remaining available AppleEvent handlers that are defined in wx.App and have them redirected to some actions with our application's main window. The following code can help us do this:
        def MacOpenURL(self, url):
            """Called in response to get-url event"""
            self.frame.AddURL(url)
    
    def MacPrintFile(self, fileName):
            """Called in response to a print-document event"""
            self.frame.PrintFile(fileName)
    
        def MacReopenApp(self):
            """Called in response to a reopen-application event"""
            if self.frame.IsIconized():
                self.frame.Iconize(False)
            self.frame.Raise()

How it works…

In the Carbon and Cocoa builds of wxPython, these additional Mac-specific virtual overrides are available for apps to implement. The app object has special handling for these events and turns them into simple function calls that can be overridden in derived applications to provide an app-specific handling of them.

The first two methods that we overrode are called in response to creating a new file or opening existing files, such as when a file is dragged and dropped in the application icon in the dock. The MacOpenFiles method is new since wxPython 2.9.3 and should be used instead of the MacOpenFile method that was provided in previous versions.

The other method that most apps should implement in some form is the MacReopenApp method. This method is called when a user clicks on the application icon in the dock. In this implementation, we ensure that the app is brought back to the foreground in response to this action.

There's more…

If there are other OS X-specific actions you want your app to handle, it is also possible to add support for additional AppleEvents to a wxPython application. It is not a particularly easy task as it requires writing a native extension module to catch the event, block the event loop, and then restore the Python interpreter's state back to wx after handling the event. There is a pretty good example that can be used as a starting point on the wxPython Wiki page (refer to http://wiki.wxpython.org/Catching%20AppleEvents%20in%20wxMAC) if you find yourself needing to venture down this route.

Left arrow icon Right arrow icon

Key benefits

  • This book empowers you to create rich cross-platform graphical user interfaces using Python
  • It helps you develop applications that can be deployed on Windows, OSX, and Linux
  • The recipes in the book involve real-world applications, giving you a first-hand experience of the practical scenarios

Description

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.

Who is this book for?

For those who are familiar with programming in Python and want to start building applications with graphical user interfaces, this book will get you up and running quickly. A basic understanding of the Python programming language and object-oriented concepts are all that is needed.

What you will learn

  • Create full featured user interfaces
  • Design and develop custom controls
  • Deploy and distribute wxPython applications to Windows, Macintosh OS X, Linux, and other UNIX-like environments
  • Handle and respond to application events
  • Manage and display data using grids
  • Interact with web services from your GUI
  • Use Paint events to draw custom displays
  • Support the display of user interfaces in multiple languages
Estimated delivery fee Deliver to Mexico

Standard delivery 10 - 13 business days

Mex$149.95

Premium delivery 3 - 6 business days

Mex$299.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 24, 2015
Length: 264 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287732
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Mexico

Standard delivery 10 - 13 business days

Mex$149.95

Premium delivery 3 - 6 business days

Mex$299.95
(Includes tracking information)

Product Details

Publication date : Dec 24, 2015
Length: 264 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287732
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,138.97
wxPython Application Development Cookbook
Mex$1004.99
Python GUI Programming Cookbook
Mex$1004.99
Python GUI Programming Cookbook, Second Edition
Mex$1128.99
Total Mex$ 3,138.97 Stars icon
Banner background image

Table of Contents

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

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(6 Ratings)
5 star 16.7%
4 star 33.3%
3 star 33.3%
2 star 16.7%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Jens Goe Feb 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I did the technical review for this book and i liked the way the book is structured. It is suitable for developers of all levels. Basic knowledge about Python and object oriented programming is recommended. This book contains a huge collection of recipes which shows how to use the various controls of wxPython 3. Every recipe describes an use case for each control followed by a code sample and a detailed explanation how the code works. Most of the samples are visualized with screenshots.The recipes starts easy with basic knowledge about graphical user interfaces and ends up with techniques to create customized controls for unique applications.
Amazon Verified review Amazon
Amazon Customer May 27, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This a pretty good book for getting started learning wxPython. The examples work just fine with the exception of trying to use a ListCtrl in a sizer, which seems to have some problems.
Amazon Verified review Amazon
Public name Oct 18, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This was a great book to get someone started with developing with wxPython. However, it is meant to be used with Python 2, and with an older version of wxPython. Many changes have been made since the book was published that require updating code.However, the concepts are still the same, and the book (even though out-dated) does not feel out-dated.
Amazon Verified review Amazon
Cici Ciconia Mar 05, 2016
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
You can find all of the samples contained in the book on the internet. This book is not comprehensive at all.
Amazon Verified review Amazon
Amazon Customer Feb 16, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
It was alright
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela