Skip to content
Related Articles

Related Articles

Improve Article

wxPython – Change cursor for ToolBar

  • Last Updated : 26 Jun, 2020

In this article will learn how can we change the cursor to a custom image cursor when it hovers over the toolbar. To do this we need to follow some steps as follows.

Step 1: Create wx.Image object of the image you like.
Step 2: Create wx.Cursor object passing image as parameter.
Step 3: Set cursor for toolbar using SetCursor() method.

wx.ToolBar.SetCursor(self, cursor)


ParameterInput TypeDescription
sizewx.SizeSize for radio button

Return Type: bool

Code Example:

import wx
class Example(wx.Frame):
    global count
    count = 0;
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        # Add tools to toolbar
        ptool = self.toolbar.AddTool(12, 'oneTool',
                                     wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
        qtool = self.toolbar.AddTool(12, 'oneTool', wx.Bitmap('wrong.png'),
                                     wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
        # create wx.Image object
        img = wx.Image('click.png')
        # create wx.Cursor object
        crsr = wx.Cursor(img)
        # set crsr cursor for the toolbar
        self.SetSize((350, 250))
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output Window:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :