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.

http://www.zetcode.com/wxpython/firststeps/self.text.SetLabel(str(value))class RightPanel(wx.Panel):def __init__(self, parent, id):wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)self.text = wx.StaticText(self, -1, '0', (40, 60))class Communicate(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(280, 200))panel = wx.Panel(self, -1)self.rightPanel = RightPanel(panel, -1)leftPanel = LeftPanel(panel, -1)hbox = wx.BoxSizer()hbox.Add(leftPanel, 1, wx.EXPAND | wx.ALL, 5)hbox.Add(self.rightPanel, 1, wx.EXPAND | wx.ALL, 5)panel.SetSizer(hbox)self.Centre()self.Show(True)app = wx.App()Communicate(None, -1, 'widgets communicate')app.MainLoop()In our example we have two panels. A left and right panel.<strong>The</strong> left panel has two buttons. <strong>The</strong> right panel has onestatic text. <strong>The</strong> buttons change the number displayed in thestatic text. <strong>The</strong> question is, how do we grab the reference tothe static text?If all the widgets are within one class, it is trivial. But whatif those widgets are created in different classes? In suchsituations, we must get the reference via the hierarchy.panel = wx.Panel(self, -1)self.rightPanel = RightPanel(panel, -1)leftPanel = LeftPanel(panel, -1)Notice that the right panel must be defined before the leftpanel. It is because during the construction of the left panel,we are looking for the static text widget, which is defined in7 de 8 27/04/2008 1:01

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

Saved successfully!

Ooh no, something went wrong!