How can I change cursors

The cursor is the most direct avatar of the user's presence on the screen. As such, it's used to provide immediate feedback to the user about the area being explored. Normally, it's a pointer to where the user's next mouse click will take effect, but depending on what widget the cursor is currently over, it can be a directional arrow, a text placement I-beam, or crosshairs. Typically, an application signals that it is too busy to accept input by changing the cursor to some kind of busy symbol, such as the classic hourglass.

You'll want to use the cursor to signal state in your application, and even though wxPython handles most of the basics for common widgets, you'll sometimes want to customize it, either because you have a custom widget or because your application needs to override the normal cursor behavior to signal a new state. Perhaps you just want your application to have its own unique cursor. In this section we'll show you how to use a cursor to signal state and how to customize cursors in wxPython.

You can create cursor objects in a variety of ways in wxPython. The cursor class is wx.Cursor, and there are two different ways of creating an instance. The simpler is the method wx.StockCursor(id), that returns an instance of a predefined system cursor. As defined in table 12.3, the id parameter can be any number of flags.

Table 12.3 Predefined stock cursors

Cursor ID



The normal arrow cursor.


A busy cursor showing both the normal arrow and an hourglass. Available on Windows systems only.


The invisible cursor. Useful when you want to trick the user.


A bullseye cursor (small circle inside a larger cursor). Sometimes useful for precision pointing.


A character cursor. Not available on all platforms.


The ever-popular cross-hair cursor.


Classic pointing hand cursor.


The vertical I-beam cursor typically used inside a text edit field.


A cursor that depicts a mouse with the left button pressed—used to hint to the user that he should press that button. May not be available on all platforms.


Magnifying glass typically used to indicate zoom.


Depicts a mouse with the middle button pressed.


Cursor containing the arrow and a circle-with-a-slash no entry symbol. Used to indicate that an area of the screen is invalid (as the target of a drag and drop, for example).


A cursor that looks like a paint brush. Typically used in a paint program.


The pencil cursor usually used in draw programs.


The cursor is a left-pointing arrow.


The cursor is a right-pointing arrow.


The arrow with the question mark next to it usually used to indicate context-sensitive help.


Just like the normal arrow cursor, but in a mirror, so that it points to the right.


A mouse with the right button pressed.

Table 12.3 Predefined stock cursors (continued)

Cursor ID



One of the cursors usually used to indicate both direction resize, this one has arrows pointing from the lower left (southwest) to upper right (northeast).


The vertical resize cursor, pointing up and down.


The other dual-direction resize cursor, pointing from lower right to upper left.


The horizontal reize cursor, pointing left and right.


Generic sizing cursor, with arrows pointing in all four compass directions.


Another painting cursor.


The hourglass wait cursor.


The watch-shaped wait cursor.

Now that we've discussed predefined cursors, we'll show you how to create custom cursors using your own images.

Creating custom cursors

You can create a custom cursor from an image using the method wx.CursorFrom-Image(image). The image parameter is a wx.lmage instance. The image is automatically resized to 32 x 32 (on MacOS 16 x 16). The mask color of the image becomes the transparent color of the cursor. By default, the hotspot is set to the (0,0) corner of the cursor image. To change that, you need to set an option in the image before you convert it:

image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 0) image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 22)

The actual wx.Cursor constructor is:

wx.Cursor(name, type, hotSpotX=0, hotSpotY=0)

The name parameter is the filename of the cursor to load. The type parameter is the icon type to load and uses the same wx.BlTMAP_TYPE_ flags as wx.lmage and wx.Bitmap. The hotSpotX and hotSpotY parameters set the hotspot of the icon. If the bitmap type used is wx.bitmap_type_cur to load from a .cur file, then the hotspot is set automatically from the hotspot defined in the .cur file.

Once you have the cursor created, using it is a simple matter of calling the SetCursor(cursor) on any wxPython widget. This method causes the cursor to be changed to the new shape when the cursor passes over the widget. There is also a global wx.SetCursor(cursor) method that globally sets the cursor for the entire application.

Images are great, but they only scratch the surface of what you can do graphically in wxPython. In the next section, we'll show how to send draw commands to the screen, or a file, or other display objects.

Was this article helpful?

+3 -3


  • violetta
    How to show hand cursor on text aream python tkinter simply?
    4 years ago
  • fiori
    How to change the cursor in python?
    9 months ago
  • hannele
    How to change the mouse cursor on python?
    4 months ago
  • arran
    How to change mouse cursor in wxpython floatcanvas?
    3 months ago

Post a comment