当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


wxPython wx.ToolBar Realize()用法及代码示例


在本文中,我们将学习与wxPython的wx.ToolBar类关联的Realize()函数。 Realize()函数,应在工具栏中进行任何操作后调用,例如添加控件,添加工具,添加分隔符等。Realize()函数不带参数。

用法:
wx.ToolBar.Realize(self)

参数:

Realize() function takes No parameters.

返回类型:

bool

代码示例1:



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

输出:

代码示例2:

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

输出:




相关用法


注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython | Realize() function in wx.ToolBar。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。