wxPython:工具栏、状态栏、菜单实现
最后更新于:2022-04-01 19:41:14
与绘制按钮一样,很简单,直接看代码:
~~~
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
import wx.py.images
class ToolbarFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Toolbars', size = (300, 200))
panel = wx.Panel(self)
panel.SetBackgroundColour('White')
#创建状态栏
statusBar = self.CreateStatusBar()
#创建工具栏
toolbar = self.CreateToolBar()
#增加一个工具
toolbar.AddSimpleTool(wx.NewId(), wx.py.images.getPyBitmap(), "New", "Long help for 'New'")
toolbar.AddSimpleTool(wx.NewId(), wx.py.images.getPyBitmap(), "Edit", "Long help for 'Edit'")
#准备显示
toolbar.Realize()
#创建菜单
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuBar.Append(menu1, "&File") #菜单项目1
menu2 = wx.Menu()
#菜单内容&表示随后的字符为热键,参数3为在状态栏上显示的菜单项说明
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.PySimpleApp()
frame = ToolbarFrame(parent = None, id = -1)
frame.Show()
app.MainLoop()
~~~
测试:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-08_5757935ee3a92.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-08_5757935f04e98.png)
';