首页 > 技术文章 > 给框架增加菜单栏,工具栏

chengyonggao 2017-09-12 23:04 原文

这段代码运行正常了但是有一个警告:大意是说要用AddTool()替换掉AddSimpleTool

试过多次都出错了,有没有人知道啊?

import wx
#import images
import wx.py.images as images
class ToolbarFrames(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,"我的程序",size=(300,200))
        panel = wx.Panel(self)  # 创建画板
        panel.SetBackgroundColour("withe")
        statusBar=self.CreateStatusBar()#创建状态栏
        toolsBar=self.CreateToolBar()#创建工具栏
        toolsBar.AddSimpleTool(wx.NewId(),images.getPyBitmap(),"New","Long help for 'new'")#给工具栏增加一个工具
        toolsBar.Realize()
        MenuBar=wx.MenuBar()
        menu1=wx.Menu()
        MenuBar.Append(menu1,"&File")
        menu2 = wx.Menu()
        menu2.Append(wx.NewId(),"&Copy","Copy in status bar")
        menu2.Append(wx.NewId(),"C&ut","")
        menu2.Append(wx.NewId(), "Paste", "")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId()," & Options...","Display Options")
        MenuBar.Append(menu2," & Edit") #  在菜单栏上附上菜单
        self.SetMenuBar(MenuBar) #  在框架上附上菜单栏
if __name__== '__main__':
    app = wx.App(False)
    frame=ToolbarFrames(parent=None, id=-1)
    frame.Show()
    app.MainLoop()

  警告原文:

wxPyDeprecationWarning: Call to deprecated item. Use :meth:`AddTool` instead.
toolsBar.AddSimpleTool(wx.NewId(),images.getPyBitmap(),"New","Long help for 'new'")#给工具栏增加一个工具

 

知道的麻烦留言告知,多谢了。

推荐阅读