在本文中,我們將學習與wxPython的wx.ToolBar類關聯的InsertSimpleTool()函數。 InsertSimpleTool()函數是在工具欄中插入工具的另一種舊方法。 InsertSimpleTool()函數將具有指定屬性的工具插入到給定位置的工具欄中。
用法:
wx.ToolBar.InsertSimplTool(self, pos, toolId, bitmap, shortHelpString="", longHelpString="", isToggle=0)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
pos | int | 從0開始要添加的工具的位置。 |
toolid | int | 一個整數,可以在隨後的操作中標識該工具。 |
bitmap | wx.bitmap | 主要工具位圖。 |
shortHelpString | string | 此字符串用於工具工具提示。 |
longHelpString | string | 與工具關聯的詳細字符串。 |
isToggle | int | 正常為0,切換按鈕為1。 |
Retun Type:
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.InsertSimpleTool(pos = 1, toolId = 2, bitmap = wx.Bitmap('right.png'), shortHelpString ="new tool one", isToggle = 0)
# insert tool at position 2
self.toolbar.InsertSimpleTool(pos = 2, toolId = 3, bitmap = wx.Bitmap('wrong.png'), shortHelpString ="new tool two", isToggle = 0)
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 FindToolForPosition()用法及代碼示例
- wxPython FindControl()用法及代碼示例
- wxPython GetClassDefaultAttributes()用法及代碼示例
- wxPython GetToolBitmapSize()用法及代碼示例
- wxPython GetMargins()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython | InsertSimpleTool() function in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。