In this article we are going to learn about Realize() function associated with wx.ToolBar class of wxPython. Realize() function which should be called after any manipulation is done in toolbar, like, adding control, adding tools, adding separations etc.. Realize() function takes no parameters.
Syntax:
wx.ToolBar.Realize(self)Parameters :
Realize() function takes No parameters.Return Type:
bool
Code Example 1:
Python3
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 ):
pnl = wx.Panel( self )
self .toolbar = self .CreateToolBar()
# Radio tool using AddTool() Function
ptool = self .toolbar.AddTool( 12 , 'oneTool' ,
wx.Bitmap( '/home / wxPython / right.png' ),
wx.Bitmap( '/home / wxPython / wrong.png' ),
kind = wx.ITEM_RADIO, shortHelp = "Simple Tool")
spc = self .toolbar.AddStretchableSpace()
# Check tool using AddTool() Function
qtool = self .toolbar.AddTool( 12 , 'oneTool' , wx.Bitmap( '/home / wxPython / right.png' ),
wx.Bitmap( '/home / wxPython / wrong.png' ),
kind = wx.ITEM_CHECK, shortHelp = "Simple Tool")
spc = self .toolbar.AddStretchableSpace()
# Normal tool using AddTool() Function
rtool = self .toolbar.AddTool( 12 , 'oneTool' , wx.Bitmap( '/home / wxPython / right.png' ),
wx.Bitmap( '/home / wxPython / wrong.png' ),
kind = wx.ITEM_NORMAL, shortHelp = "Simple Tool")
# Realize() is called to finalize all added tools
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()
|
Output:
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(' 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):
self .toolbar.InsertTool(pos = 1 , toolId = 2 , label = 'wrong' , bitmap = wx.Bitmap( 'wrong.png' ))
self .toolbar.InsertTool(pos = 2 , toolId = 3 , label = 'right' , bitmap = wx.Bitmap( 'right.png' ))
# 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:
Article Tags :