wxPython | Realize() function in wx.ToolBar

In this article we are going to learn about Realize() function associated wit 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:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Code Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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.




My Personal Notes arrow_drop_up

Hi there I am a student of CGC COE, Landran in CSE department and have a great interest in programming

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.