13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>wxPython</strong> griptshttp://www.zetcode.com/wxpython/gripts/Notice that each time the window is resized, we must position our icon to anew place.def PlaceIcon(self):rect = self.GetFieldRect(1)self.icon.SetPosition((rect.x+3, rect.y+3))PuzzleIn this gript, we introduce a puzzle game. We have an image of a Sidcharacter from the Ice Age movie. It is cut into 9 pieces and shuffled. <strong>The</strong>goal is to form the picture.Figure: Puzzle#!/usr/bin/python# puzzle.pyimport wximport randomclass Puzzle(wx.Dialog):def __init__(self, parent, id, title):wx.Dialog.__init__(self, parent, id, title)images = ['images/one.jpg', 'images/two.jpg', 'images/three.jpg', 'images/four.jpg','images/five.jpg', 'images/six.jpg', 'images/seven.jpg', 'images/eight.jpg']self.pos = [ [0, 1, 2], [3, 4, 5], [6, 7, 8] ]self.sizer = wx.GridSizer(3, 3, 0, 0)numbers = [0, 1, 2, 3, 4, 5, 6, 7]random.shuffle(numbers)for i in numbers:button = wx.BitmapButton(self, i, wx.Bitmap(images[i]))button.Bind(wx.EVT_BUTTON, self.OnPressButton, id=button.GetId())10 de 12 27/04/2008 1:09

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

Saved successfully!

Ooh no, something went wrong!