Skip to content
Related Articles

Related Articles

Improve Article

wxPython | InsertSimpleTool() function in python

  • Last Updated : 04 Jun, 2020

In this article we are going to learn about InsertSimpleTool() function associated with wx.ToolBar class of wxPython. InsertSimpleTool() function is another old style method to insert a tool in the toolbar. InsertSimpleTool() function inserts the tool with the specified attributes into the toolbar at the given position.

Syntax:

wx.ToolBar.InsertSimplTool(self, pos, toolId, bitmap, shortHelpString="", longHelpString="", isToggle=0)

Parameters:

ParameterInput TypeDescription
posintPosition of tool to be added starting from 0.
toolidintAn integer by which the tool may be identified in subsequent operations.
bitmapwx.bitmapThe primary tool bitmap.
shortHelpStringstringThis string is used for the tools tooltip.
longHelpStringstringdetailed string associated with tool.
isToggleint0 for normal 1 for toggle button.

Retun Type:

wx.ToolBarToolBase

Code Example 1:






import wx
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.InitUI()
  
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.toolbar = self.CreateToolBar()
        td = self.toolbar.AddTool(1, '', wx.Bitmap('user.png'))
  
        self.toolbar.Realize()
        self.Bind(wx.EVT_TOOL, self.OnOne, td)
  
        self.SetSize((350, 250))
        self.SetTitle('Undo redo')
        self.Centre()
  
    def OnOne(self, e):
        # insert tool at position 1
        self.toolbar.InsertSimpleTool(pos = 1, toolId = 2, bitmap = wx.Bitmap('right.png'), shortHelpString ="new tool one", isToggle = 0)
        # insert tool at position 2
        self.toolbar.InsertSimpleTool(pos = 2, toolId = 3, bitmap = wx.Bitmap('wrong.png'), shortHelpString ="new tool two", isToggle = 0)
        self.toolbar.Realize()
  
    def OnQuit(self, e):
        self.Close()
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

Output :
before clicking profile icon:

after clicking profile icon:

 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 :