wxPython:简单的wxPython程序

  最近自学wxPython,参考书籍为《wxPython in Action》,所以最近的一系列wxPython相关文章均为读书笔记。

  先来个简单的wxPython程序热热身。

 代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
    Function:简单的wxPython程序
    Input:NONE
    Output: NONE
    author: socrates
    blog:http://www.cnblogs.com/dyx1024/
    date:2012-06-30
'''       
    
import wx

class MyFrame(wx.Frame):
    '''
    创建一个Frame类
    '''
    def __init__(self, image, parent = None, id = -1,
                 pos = wx.DefaultPosition,
                 title = u"Hello wxPython"):
        temp = image.ConvertToBitmap()
        size = temp.GetWidth(), temp.GetHeight() #图片的大小用做窗口大小
        wx.Frame.__init__(self, parent, id, title, pos, size)
        self.bmp = wx.StaticBitmap(parent = self, bitmap = temp)
              
class MyApp(wx.App):
    '''
    创建一个App类
    '''
    def OnInit(self):
        image = wx.Image('back_image.jpg', wx.BITMAP_TYPE_JPEG) #加载国片
        self.frame = MyFrame(image)
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True
    
def main():
    app = MyApp()
    app.MainLoop()    
    
if __name__ == '__main__':
    main()  

运行结果:

 

 

posted @ 2012-07-01 00:05  Socrates  阅读(833)  评论(0编辑  收藏  举报