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/# enabledisable.pyimport wxclass EnableDisable(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 150))self.count = 5self.toolbar = self.CreateToolBar()self.toolbar.AddLabelTool(wx.ID_UNDO, '', wx.Bitmap('../icons/undo.png'))self.toolbar.AddLabelTool(wx.ID_REDO, '', wx.Bitmap('../icons/redo.png'))self.toolbar.EnableTool(wx.ID_REDO, False)self.toolbar.AddSeparator()self.toolbar.AddLabelTool(wx.ID_EXIT, '', wx.Bitmap('../icons/exit.png'))self.toolbar.Realize()self.Bind(wx.EVT_TOOL, self.OnExit, id=wx.ID_EXIT)self.Bind(wx.EVT_TOOL, self.OnUndo, id=wx.ID_UNDO)self.Bind(wx.EVT_TOOL, self.OnRedo, id=wx.ID_REDO)self.Centre()self.Show(True)def OnUndo(self, event):if self.count > 1 and self.count = 1:self.count = self.count + 1if self.count == 5:self.toolbar.EnableTool(wx.ID_REDO, False)if self.count == 2:self.toolbar.EnableTool(wx.ID_UNDO, True)def OnExit(self, event):self.Close()app = wx.App()EnableDisable(None, -1, 'enable disable')app.MainLoop()In our example, we have three toolbar buttons. One button is for exitingthe application. <strong>The</strong> other two buttons are undo and redo buttons. <strong>The</strong>ysimulate undo/redo functionality in an application. (for a real example,see tips and tricks) We have 4 changes. <strong>The</strong> undo and redo butons aredisabled accordingly.self.toolbar.EnableTool(wx.ID_REDO, False)self.toolbar.AddSeparator()In the beginning, the redo button is disabled. We do it by calling the14 de 15 27/04/2008 1:02

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

Saved successfully!

Ooh no, something went wrong!