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


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

在本文中,我們將學習與wxPython中的類wx.ToolBar關聯的InsertLabelTool()函數。 InsertLabelTool()是在工具欄中插入工具的舊方法。 InsertLabelTool()將刀具的不同屬性作為參數插入刀具。

用法:
wx.ToolBar.InsertLabelTool(self, pos, id, label, bitmap, bmpDisabled=wx.NullBitmap, kind=wx.ITEM_NORMAL, shortHelp="", longHelp="", clientData=None)

參數:

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

返回類型:

wx.ToolBarToolBase

代碼示例1:

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('user.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 at position 1 
        self.toolbar.InsertLabelTool( pos = 1, id = 3, label ='new tool1', bitmap = wx.Bitmap('right.png'), kind = wx.ITEM_NORMAL, shortHelp ="nono") 
        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 | InsertLabelTool() function in wx.ToolBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。