13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Menus and Toolbars in <strong>wxPython</strong>http://www.zetcode.com/wxpython/menustoolbars/<strong>wxPython</strong> Coding ToolsHome ContentsDebugger, Browser, Editor, and more Take aTest Flight Today!Get a WebSearch toolbarTry these Websearch toolbars built withDynamic ToolbarMenus and Toolbars in <strong>wxPython</strong>Creating a MenuBarA menubar is one of the most visible parts of the GUI application. It is agroup of commands located in various menus. While in consoleapplications you had to remember all those arcane commands, here wehave most of the commands grouped into logical parts. <strong>The</strong>re areaccepted standards that further reduce the amount of time spending tolearn a new application. To implement a menubar in <strong>wxPython</strong> we needto have three things. A wx.MenuBar, a wx.Menu and a wx.MenuItem.Figure: A MenuBar architectureA Simple menu exampleCreating a menubar in <strong>wxPython</strong> is very simple. Just a few lines of code.#!/usr/bin/python# simplemenu.pyimport wxclass SimpleMenu(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 150))menubar = wx.MenuBar()file = wx.Menu()file.Append(-1, 'Quit', 'Quit application')menubar.Append(file, '&File')self.SetMenuBar(menubar)self.Centre()1 de 15 27/04/2008 1:02

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!