wxPython wx.ToolBar中的Realize()函数

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

输出:

wxPython wx.ToolBar中的Realize函数

代码示例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()

输出:

wxPython wx.ToolBar中的Realize函数

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

wxPython 教程