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/def ToggleStatusBar(self, event):if self.shst.IsChecked():self.statusbar.Show()else:self.statusbar.Hide()def ToggleToolBar(self, event):if self.shtl.IsChecked():self.toolbar.Show()else:self.toolbar.Hide()app = wx.App()CheckMenuItem(None, -1, 'check menu item')app.MainLoop()self.shst = view.Append(ID_STAT, 'Show statubar', 'Show Statusbar', kind=wx.ITEM_CHECK)self.shtl = view.Append(ID_TOOL, 'Show toolbar', 'Show Toolbar', kind=wx.ITEM_CHECK)If we want to append a check menu item, we set a kind parameter towx.ITEM_CHECK. <strong>The</strong> default parameter is wx.ITEM_NORMAL. <strong>The</strong>Append() method returns a wx.MenuItem.view.Check(ID_STAT, True)view.Check(ID_TOOL, True)When the application starts, both statusbar and toolbar are visible. Sowe check both menu items with the Check() method.def ToggleStatusBar(self, event):if self.shst.IsChecked():self.statusbar.Show()else:self.statusbar.Hide()We show or hide the statusbar according to the state of the check menuitem. We find out the state of the check menu item with the IsChecked()method. Same with toolbar.8 de 15 27/04/2008 1:02

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

Saved successfully!

Ooh no, something went wrong!