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/character and the shortcut. This way, we manage to put some spacebetween them. To provide an icon for a menuitem, we call a SetBitmap()method. A manually created menuitem is appended to the menu bycalling the AppendItem() method.self.Bind(wx.EVT_MENU, self.OnQuit, id=1)If we select a quit menu item or press a keyboard shortcut, awx.EVT_MENU event is generated. We bind an event handler to theevent. <strong>The</strong> event handler is a method, that is being called. In ourexample, the OnQuit() method closes the application. <strong>The</strong>re can beseveral menuitems, so we have to give a unique id to each of them.Working with events is very easy and straightforward in <strong>wxPython</strong>. Wewill talk about events in a separate chapter.Figure: A menu exampleSubmenusEach menu can also have a submenu. This way we can group similarcommnads into groups. For example we can place commands thathide/show various toolbars like personal bar, address bar, status bar ornavigation bar into a submenu called toolbars. Within a menu, we canseperate commands with a separator. It is a simple line. It is commonpractice to separate commands like new, open, save from commands likeprint, print preview with a single separator. In our example we will see,how we can create submenus and menu separators.#!/usr/bin/python# submenu.pyimport wxID_QUIT = 1class SubmenuExample(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(350, 250))menubar = wx.MenuBar()file = wx.Menu()5 de 15 27/04/2008 1:02

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

Saved successfully!

Ooh no, something went wrong!