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.

<strong>wxPython</strong> widgetshttp://www.zetcode.com/wxpython/widgets/wx.ToggleButton is a button that has two states. Pressed and notpressed. You toggle between these two states by clicking on it.<strong>The</strong>re are situations where this functionality fits well.Figure: Togglebuttons.py#!/usr/bin/python# togglebuttons.pyimport wxclass ToggleButtons(wx.Dialog):def __init__(self, parent, id, title):wx.Dialog.__init__(self, parent, id, title, size=(300, 200))self.colour = wx.Colour(0, 0, 0)wx.ToggleButton(self, 1, 'red', (20, 25))wx.ToggleButton(self, 2, 'green', (20, 60))wx.ToggleButton(self, 3, 'blue', (20, 100))self.panel = wx.Panel(self, -1, (150, 20), (110, 110), style=wx.SUNKEN_BORself.panel.SetBackgroundColour(self.colour)self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleRed, id=1)self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleGreen, id=2)self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleBlue, id=3)self.Centre()self.ShowModal()self.Destroy()def ToggleRed(self, event):green = self.colour.Green()blue = self.colour.Blue()if self.colour.Red():self.colour.Set(0, green, blue)else:self.colour.Set(255, green, blue)self.panel.SetBackgroundColour(self.colour)3 de 29 27/04/2008 1:04

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

Saved successfully!

Ooh no, something went wrong!