📜  wxPython – 更改工具栏的光标

📅  最后修改于: 2022-05-13 01:54:18.995000             🧑  作者: Mango

wxPython – 更改工具栏的光标

在本文中,我们将学习如何将光标悬停在工具栏上时将光标更改为自定义图像光标。为此,我们需要遵循以下一些步骤。

代码示例:

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()

输出窗口: