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.

Events in <strong>wxPython</strong>http://www.zetcode.com/wxpython/events/Each widget has an id parameter. This is a unique number in theevent system. If we work with multiple widgets, we mustdifferantiate among them.wx.Button(parent, -1)wx.Button(parent, wx.ID_ANY)If we provide -1 or wx.ID_ANY for the id parameter, we let the<strong>wxPython</strong> automatically create an id for us. <strong>The</strong> automaticallycreated id's are always negative, whereas user specified id'smust always be positive. We usually use this option when we donot need to change the widget state. For example a static text,that will never be changed during the life of the application. Wecan still get the id, if we want. <strong>The</strong>re is a method GetId(), whichwill determine the id for us.#!/usr/bin/python# automaticids.pyimport wxclass AuIds(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(170, 100))panel = wx.Panel(self, -1)exit = wx.Button(panel, -1, 'Exit', (10, 10))self.Bind(wx.EVT_BUTTON, self.OnExit, id=exit.GetId())self.Centre()self.Show(True)def OnExit(self, event):self.Close()app = wx.App()AuIds(None, -1, '')app.MainLoop()In this example, we do not care about the actual id value.self.Bind(wx.EVT_BUTTON, self.OnExit, id=exit.GetId())We get the automatically generated id by calling the GetId()method.7 de 14 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!