Python – wxPython 中的 AddCheckTool()函数
在本文中,我们将学习 wxPython 的 wx.ToolBar 类中的 AddCheckTool()。 AddCheckTool()函数用于添加检查工具。检查工具是一种切换按钮。检查工具有开和关状态。
Syntax : wx.ToolBar.AddCheckTool(self, toolId, label, bitmap1, bmpDisabled=NullBitmap, shortHelp=””, longHelp=””, clientData=None)
Parameters :
Parameter | Input Type | Description |
---|---|---|
toolid | int | An integer by which the tool may be identified in subsequent operations. |
label | string | The string to be displayed with the tool. |
bitmap1 | wx.bitmap | The primary tool bitmap. |
bmpDisabled | wx.bitmap | The bitmap used when the tool is disabled. |
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):
global count
count = 0;
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
pnl = wx.Panel(self)
self.toolbar = self.CreateToolBar()
# create check toolusing AddCheckTool() function
rtool = self.toolbar.AddCheckTool(12, 'CheckTool',
bitmap1 = wx.Bitmap('/Desktop/wxPython/right.png'),
bmpDisabled = wx.Bitmap('/Desktop/wxPython/wrong.png'))
self.toolbar.Realize()
self.SetSize((350, 250))
self.SetTitle('Simple toolbar')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出 :
未选中:
检查: