當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.ToolBar InsertTool()用法及代碼示例

在本文中,我們將學習與wxPython的wx.ToolBar類關聯的InsertTool()函數。 InsertTool()函數是將工具插入特定位置的新樣式。 InsertTool()將與工具關聯的參數作為其參數。

用法: wx.ToolBar.InsertTool (self, pos, toolId, label, bitmap, bmpDisabled=NullBitmap, kind=ITEM_NORMAL, shortHelp=””, longHelp=””, clientData=None)

參數:

參數 輸入類型 描述
pos int 從0開始添加工具的位置。
toolid int 一個整數,可以在隨後的操作中標識該工具。
label string 該工具將顯示的字符串。
bitmap wx.bitmap 主要工具位圖。
bmpDisabled wx.bitmap 禁用工具時使用的位圖。
kind int 一種工具欄。
shortHelp string 此字符串用於工具工具提示。
longHelp string 與工具關聯的詳細字符串。
clientData PyUserData 客戶端數據的可選指針,以後可以使用GetToolClientData檢索。

返回類型:
wx.ToolBarToolBase

代碼示例:

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):
        # insert tool with id = 2 
        self.toolbar.InsertTool(pos = 1, toolId = 2, label ='wrong', 
                                   bitmap = wx.Bitmap('wrong.png')) 
        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()

輸出:
在單擊單獨的工具之前:

單擊單獨的工具後:

代碼示例:

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):
        # insert two tools in one go 
        self.toolbar.InsertTool(pos = 3, toolId = 2, label ='wrong',  
                                   bitmap = wx.Bitmap('wrong.png')) 
        self.toolbar.InsertTool(pos = 4, toolId = 3, label ='right',  
                                    bitmap = wx.Bitmap('right.png')) 
        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 – InsertTool() function in wx.ToolBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。