In this article we are going to learn about RemoveTool() function associated with wx.ToolBar class of wxPython. RemoveTool() removes the given tool from the toolbar but doesn’t delete it. This allows inserting/adding this tool back to this (or another) toolbar later. RemoveTool() takes only id as parameter.
Syntax:
wx.ToolBar.RemoveTool(self, id)Parameters :
Parameter Input Type Description id int ID of the tool in question, as passed to AddTool . 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(' wrong.png'))
te = self .toolbar.AddTool( 2 , ' ', wx.Bitmap(' right.png'))
tf = self .toolbar.AddTool( 3 , ' ', wx.Bitmap(' sep.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):
# delete tools from toolbar using RemoveTool() function
self .toolbar.RemoveTool( id = 2 )
self .toolbar.RemoveTool( id = 3 )
# Realize() called to finalize new added tools
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 cross tool:
Article Tags :