Skip to content
Related Articles

Related Articles

wxPython – Change Cursor on hover on Button

View Discussion
Improve Article
Save Article
  • Last Updated : 23 Jan, 2022

In this article we will learn that how can we change cursor when it hovers on Button present in frame. We need to follow some steps as followed.

Step 1- Create a wx.Image object with image you want to use as cursor image. 
Step 2- Create a wx.Cursor object and pass wx.Image object above created. 
Step 3- Set the cursor using SetCursor() function.


Syntax: wx.Button.SetCursor(cursor)


ParameterInput TypeDescription
cursorwx.Cursorcursor to be set.


Code Example: 


import wx
class Example(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.pnl = wx.Panel(self)
        # CREATE BUTTON AT POINT (20, 20) = wx.Button(self.pnl, id = 1, label ="Button", pos =(20, 20),
                                size = wx.DefaultSize,  name ="button")
        c = wx.Cursor(wx.Image('pointer.png'))
        # SET c AS CURSOR
        self.SetSize((350, 250))
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output Window: 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!