在本文中,我們將學習與wxPython的wx.ToolBar類關聯的InsertControl()函數。 InsertControl()將控件插入到給定位置的工具欄中。請注意,您必須致電Realize才能進行更改。
用法:
wx.ToolBar.InsertControl(self, pos, control, label="")
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
pos | int | 從0開始定位插入控件的位置。 |
control | wx.Control | 控製要插入的內容。 |
label | string | 要在控件上顯示的標簽。 |
返回類型:
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()
tundo = self.toolbar.AddTool(1, '', wx.Bitmap('right.png'))
tredo = self.toolbar.AddTool(2, '', wx.Bitmap('wrong.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.OnOne, tundo)
self.SetSize((350, 250))
self.SetTitle('Undo redo')
self.Centre()
def OnOne(self, e):
ctrl = wx.Control(self.toolbar, id = 1, size =(100, -1),
style = 0, name ="control")
# insert control in toolbar at position 2
self.toolbar.InsertControl(pos = 2, control = ctrl, label ="Control")
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()
tundo = self.toolbar.AddTool(1, '', wx.Bitmap('right.png'))
tredo = self.toolbar.AddTool(2, '', wx.Bitmap('wrong.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.OnOne, tundo)
self.SetSize((350, 250))
self.SetTitle('Undo redo')
self.Centre()
def OnOne(self, e):
ctrl = wx.Control(self.toolbar, id = 1, size =(100, -1),
style = 0, name ="control")
# insert control in toolbar at position 2
self.toolbar.InsertControl(pos = 0, control = ctrl, label ="Control")
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 wx.StaticText GetLabel()用法及代碼示例
- wxPython FindToolForPosition()用法及代碼示例
- wxPython wx.ToolBar GetToolState()用法及代碼示例
- wxPython wx.StaticText SetBackgroundColour()用法及代碼示例
- wxPython GetToolEnabled()用法及代碼示例
- wxPython wx.StaticText SetForegroundColour()用法及代碼示例
- wxPython FindControl()用法及代碼示例
- wxPython GetToolBitmapSize()用法及代碼示例
- wxPython GetToolByPos()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython | InsertControl() function in wx.ToolBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。