wxPython | wx.ToolBar 中的 InsertSeparator()函数
在本文中,我们将学习与 wxPython 的 wx.ToolBar 类关联的 InsertSeparator()函数。 InsertSeparator()函数只是将分隔符插入到工具栏的给定位置。请注意,您必须调用 Realize 才能进行更改。它只需要 pos 作为参数。
Syntax:
Parameter :Parameter Input Type Description pos int position to insert separation starting from 0.
Return Type:
代码示例 1:
Python3
wx.ToolBar.InsertSeparator(self, pos)
Python3
wx.ToolBarToolBase
输出:单击单独图标之前: 单击单独的图标后:
代码示例 2:
Python3
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'))
te = self.toolbar.AddTool(2, '', wx.Bitmap('right.png'))
tf = self.toolbar.AddTool(3, '', wx.Bitmap('wrong.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 separator b / w tick and cross tool
self.toolbar.InsertSeparator( pos = 2)
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()
输出:单击单独图标之前: 单击单独的图标后: