Open In App

wxPython | InsertSimpleTool() function in python

Improve
Improve
Like Article
Like
Save
Share
Report

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.InsertSimpleTool(self, pos, toolId, bitmap, shortHelpString="", longHelpString="", isToggle=0)

Parameters: 

Parameter Input Type Description
pos int Position of tool to be added starting from 0.
toolid int An integer by which the tool may be identified in subsequent operations.
bitmap wx.bitmap The primary tool bitmap.
shortHelpString string This string is used for the tools tooltip.
longHelpString string detailed string associated with tool.
isToggle int 0 for normal 1 for toggle button.

Return Type: 

wx.ToolBarToolBase

 

Code Example 1:

Python3




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: 

 



Last Updated : 27 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads