在本文中,我们将学习与wxPython中的类wx.ToolBar关联的GetToolsCount()函数。 GetToolsCount()函数仅返回工具栏中的工具数量。 GetToolsCount()函数不带参数。
用法:
wx.ToolBar.GetToolsCount(self)
参数:
No parameters are required in GetToolsCount() function.
返回类型:
int
代码示例1:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.count = 5
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.toolbar = self.CreateToolBar()
tundo = self.toolbar.AddTool(wx.ID_UNDO, '', wx.Bitmap('right.png'))
tredo = self.toolbar.AddTool(wx.ID_REDO, '', wx.Bitmap('wrong.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.OnUndo, tundo)
self.Bind(wx.EVT_TOOL, self.OnRedo, tredo)
print(self.ToolBar.GetToolsCount())
self.SetSize((350, 250))
self.SetTitle('Undo redo')
self.Centre()
def OnUndo(self, e):
if self.count > 1 and self.count <= 5:
self.count = self.count - 1
if self.count == 1:
self.toolbar.EnableTool(wx.ID_UNDO, False)
if self.count == 4:
self.toolbar.EnableTool(wx.ID_REDO, True)
def OnRedo(self, e):
if self.count < 5 and self.count >= 1:
self.count = self.count + 1
if self.count == 5:
self.toolbar.EnableTool(wx.ID_REDO, False)
if self.count == 2:
self.toolbar.EnableTool(wx.ID_UNDO, True)
def OnQuit(self, e):
self.Close()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出:
窗口:
打印输出:
2
代码示例2:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.count = 5
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.toolbar = self.CreateToolBar()
tundo = self.toolbar.AddTool(wx.ID_UNDO, '', wx.Bitmap('right.png'))
tredo = self.toolbar.AddTool(wx.ID_REDO, '', wx.Bitmap('wrong.png'))
tperson = self.toolbar.AddTool(wx.ID_REDO, '', wx.Bitmap('user.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.OnUndo, tundo)
self.Bind(wx.EVT_TOOL, self.OnRedo, tredo)
print(self.ToolBar.GetToolsCount())
self.SetSize((350, 250))
self.SetTitle('Undo redo')
self.Centre()
def OnUndo(self, e):
if self.count > 1 and self.count <= 5:
self.count = self.count - 1
if self.count == 1:
self.toolbar.EnableTool(wx.ID_UNDO, False)
if self.count == 4:
self.toolbar.EnableTool(wx.ID_REDO, True)
def OnRedo(self, e):
if self.count < 5 and self.count >= 1:
self.count = self.count + 1
if self.count == 5:
self.toolbar.EnableTool(wx.ID_REDO, False)
if self.count == 2:
self.toolbar.EnableTool(wx.ID_UNDO, True)
def OnQuit(self, e):
self.Close()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出:
窗口:
打印输出:
3
相关用法
- wxPython wx.StaticText GetLabel()用法及代码示例
- wxPython FindToolForPosition()用法及代码示例
- wxPython wx.ToolBar GetToolState()用法及代码示例
- wxPython wx.StaticText SetBackgroundColour()用法及代码示例
- wxPython wx.StaticText SetForegroundColour()用法及代码示例
- wxPython GetToolEnabled()用法及代码示例
- wxPython FindControl()用法及代码示例
- wxPython GetToolBitmapSize()用法及代码示例
- wxPython GetToolByPos()用法及代码示例
注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython | GetToolsCount() function in wx.ToolBar。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。