21.01.2015 Views

wxPython in Action - 错误提示:发生了异常

wxPython in Action - 错误提示:发生了异常

wxPython in Action - 错误提示:发生了异常

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.

1.4 hello.py<br />

<br />

#!/usr/b<strong>in</strong>/env python<br />

“””Hello, <strong>wxPython</strong>! program.”””<br />

import wx<br />

class Frame(wx.Frame): #2 wx.Frame<br />

”””Frame class that displays an image.”””<br />

def __<strong>in</strong>it__(self, image, parent=None, id=-1,<br />

pos=wx.DefaultPosition,<br />

title=’Hello, <strong>wxPython</strong>!’): #3<br />

”””Create a Frame <strong>in</strong>stance and display image.”””<br />

#4 <br />

temp = image.ConvertToBitmap()<br />

size = temp.GetWidth(), temp.GetHeight()<br />

wx.Frame.__<strong>in</strong>it__(self, parent, id, title, pos, size)<br />

self.bmp = wx.StaticBitmap(parent=self, bitmap=temp)<br />

class App(wx.App): #5 wx.App<br />

”””Application class.”””<br />

def OnInit(self):<br />

#6 <br />

image = wx.Image(‘<strong>wxPython</strong>.jpg’, wx.BITMAP_TYPE_JPEG)<br />

self.frame = Frame(image)<br />

self.frame.Show()<br />

self.SetTopW<strong>in</strong>dow(self.frame)<br />

return True<br />

def ma<strong>in</strong>(): #7<br />

app = App()<br />

app.Ma<strong>in</strong>Loop()<br />

26 / 565

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

Saved successfully!

Ooh no, something went wrong!