Friday, October 24, 2025
HomeLanguageswxPython – Change cursor for ToolBar

wxPython – Change cursor for ToolBar

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.

Syntax:
wx.ToolBar.SetCursor(self, cursor)

Parameters:

Parameter Input Type Description
size wx.Size Size 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)
  
        self.InitUI()
  
    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('right.png'),
                                     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.toolbar.SetCursor(crsr)
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output Window:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS