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/Figure: check menu itemContext menuIt is a list of commands that appears under some context. For example,in a Firefox web browser, when we right click on a web page, we get acontext menu. Here we can reload a page, go back or view page source.If we right click on a toolbar, we get another context menu for managingtoolbars. Context menus are sometimes called popup menus.#!/usr/bin/python# contextmenu.pyimport wxclass MyPopupMenu(wx.Menu):def __init__(self, parent):wx.Menu.__init__(self)self.parent = parentminimize = wx.MenuItem(self, wx.NewId(), 'Minimize')self.AppendItem(minimize)self.Bind(wx.EVT_MENU, self.OnMinimize, id=minimize.GetId())close = wx.MenuItem(self, wx.NewId(), 'Close')self.AppendItem(close)self.Bind(wx.EVT_MENU, self.OnClose, id=close.GetId())def OnMinimize(self, event):self.parent.Iconize()def OnClose(self, event):self.parent.Close()class ContextMenu(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 150))self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)self.Center()self.Show()def OnRightDown(self, event):self.PopupMenu(MyPopupMenu(self), event.GetPosition())app = wx.App()frame = ContextMenu(None, -1, 'context menu')app.MainLoop()class MyPopupMenu(wx.Menu):def __init__(self, parent):9 de 15 27/04/2008 1:02

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

Saved successfully!

Ooh no, something went wrong!