wxPython – wx.ToolBar 中的 InsertTool()函数
在本文中,我们将学习与 wxPython 的 wx.ToolBar 类关联的 InsertTool()函数。 InsertTool()函数是将工具插入工具栏中特定位置的新样式。 InsertTool() 将与工具关联的参数作为其参数。
Syntax: wx.ToolBar.InsertTool (self, pos, toolId, label, bitmap, bmpDisabled=NullBitmap, kind=ITEM_NORMAL, shortHelp=””, longHelp=””, clientData=None)
Parameters:
Parameter | Input Type | Description |
---|---|---|
pos | int | Position to add tools starting from 0. |
toolid | int | An integer by which the tool may be identified in subsequent operations. |
label | string | The string to be displayed with the tool. |
bitmap | wx.bitmap | The primary tool bitmap. |
bmpDisabled | wx.bitmap | The bitmap used when the tool is disabled. |
kind | int | kind of toolbar. |
shortHelp | string | This string is used for the tools tooltip. |
longHelp | string | detailed string associated with tool. |
clientData | PyUserData | An optional pointer to client data which can be retrieved later using GetToolClientData. |
Return Type:
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()
输出 :
在单击单独的工具之前:
单击单独的工具后:
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。