在本文中,我們將學習與wxPython的wx.ToolBar類關聯的InsertSeparator()函數。 InsertSeparator()函數隻是將分隔符插入到工具欄的給定位置。請注意,您必須致電Realize才能進行更改。它僅使用pos作為參數。
用法:
wx.ToolBar.InsertSeparator(self, pos)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
pos | int | 從0開始插入分隔符的位置。 |
返回類型:
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('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()
輸出:
在單擊單獨的圖標之前:
單擊單獨的圖標後:
代碼示例2:
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):
for i in range(5):
# insert 5 separator 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()
輸出:
在單擊單獨的圖標之前:
單擊單獨的圖標後:
相關用法
- wxPython GetToolPacking()用法及代碼示例
- wxPython wx.ToolBar GetToolState()用法及代碼示例
- wxPython wx.StaticText SetBackgroundColour()用法及代碼示例
- wxPython wx.StaticText SetForegroundColour()用法及代碼示例
- wxPython GetToolByPos()用法及代碼示例
- wxPython wx.StaticText GetLabel()用法及代碼示例
- wxPython GetToolPos()用法及代碼示例
- wxPython GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.ToolBar AddTool()用法及代碼示例
- wxPython FindToolForPosition()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython | InsertSeparator() function in wx.ToolBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。