wxPython 在python中插入SimpleTool()函数

wxPython 在python中插入SimpleTool()函数

在这篇文章中,我们将学习与wxPython的wx.ToolBar类相关的InsertSimpleTool()函数。InsertSimpleTool()函数是另一种在工具栏中插入工具的老式方法。InsertSimpleTool()函数将具有指定属性的工具插入到工具栏的指定位置。

语法

wx.ToolBar.InsertSimplTool(self, pos, toolId, bitmap, shortHelpString="", longHelpString="", isToggle=0)
Python

参数

参数 输入类型 描述
pos int 要添加的刀具的位置,从0开始。
toolid int 一个整数,可以在后续操作中识别该工具。
bitmap wx.bitmap 主要的工具位图。
shortHelpString 字符串 这个字符串用于工具的工具提示。
longHelpString 字符串 与工具相关的详细字符串。
isToggle int 0表示正常,1表示切换按钮。

返回类型

wx.ToolBarToolBase
Python

代码实例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('user.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 tool at position 1
        self.toolbar.InsertSimpleTool(pos = 1, toolId = 2, bitmap = wx.Bitmap('right.png'), shortHelpString ="new tool one", isToggle = 0)
        # insert tool at position 2
        self.toolbar.InsertSimpleTool(pos = 2, toolId = 3, bitmap = wx.Bitmap('wrong.png'), shortHelpString ="new tool two", isToggle = 0)
        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()
Python

输出:

在点击简介图标之前。

wxPython  在python中插入SimpleTool()函数

点击简介图标后。

wxPython  在python中插入SimpleTool()函数

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

wxPython 教程

登录

注册