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/self.Show(True)app = wx.App()SimpleMenu(None, -1, 'simple menu example')app.MainLoop()menubar = wx.MenuBar()First we create a menubar object.file = wx.Menu()Next we create a menu object.file.Append(-1, 'Quit', 'Quit application')We append a menu item into the menu object. <strong>The</strong> first parameter is theid of the menu item. <strong>The</strong> second parameter is the name of the menuitem. <strong>The</strong> last parameter defines the short helpstring that is displayed onthe statusbar, when the menu item is selected. Here we did not create awx.MenuItem explicitely. It was created by the Append() method behindthe scenes. Later on, we will create a wx.MenuItem manually.menubar.Append(file, '&File')self.SetMenuBar(menubar)After that, we append a menu into the menubar. <strong>The</strong> & character createsan accelerator key. <strong>The</strong> character that follows the & is underlined. Thisway the menu is accessible via the alt + F shortcut. In the end, we callthe SetMenuBar() method. This method belongs to the wx.Frame widget.It sets up the menubar.Figure: A simple menu exampleA dockable menubarUnder Linux, we can create a dockable menubar. This feature is notcommoly seen in applications. But similar thing can be seen on Mac OS.Mac users do not have a menubar in the toplevet application window.<strong>The</strong> menubar is implemented outside the main window.2 de 15 27/04/2008 1:02

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

Saved successfully!

Ooh no, something went wrong!