13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Menus and Toolbars in <strong>wxPython</strong>http://www.zetcode.com/wxpython/menustoolbars/app.MainLoop()toolbar.AddLabelTool(wx.ID_EXIT, '', wx.Bitmap('../icons/exit.png'))To create a toolbar button, we call the AddLabelTool() method.toolbar.Realize()After we have put our items to the toolbar, we call the Realize() method.Calling this method is not obligatory on Linux. On windows it is.self.Bind(wx.EVT_TOOL, self.OnExit, id=wx.ID_EXIT)To handle toolbar events, we use the wx.EVT_TOOL event binder.Figure: simple toolbarIf we want to create more than one toolbars, we must do it differently.#!/usr/bin/python# toolbars.pyimport wxclass Toolbars(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(300, 200))vbox = wx.BoxSizer(wx.VERTICAL)toolbar1 = wx.ToolBar(self, -1)toolbar1.AddLabelTool(wx.ID_ANY, '', wx.Bitmap('../icons/new.png'))toolbar1.AddLabelTool(wx.ID_ANY, '', wx.Bitmap('../icons/open.png'))toolbar1.AddLabelTool(wx.ID_ANY, '', wx.Bitmap('../icons/save.png'))toolbar1.Realize()toolbar2 = wx.ToolBar(self, -1)toolbar2.AddLabelTool(wx.ID_EXIT, '', wx.Bitmap('../icons/exit.png'))toolbar2.Realize()11 de 15 27/04/2008 1:02

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

Saved successfully!

Ooh no, something went wrong!