分享

wxPython 窗口用图片做背景

 星光闪亮图书馆 2017-12-28

效果图:


实现代码:

  1. #!/usr/bin/env python  
  2. # -*- encoding:utf-8 -*-  
  3.   
  4. import wx  
  5.   
  6.   
  7. class MyPanel(wx.Panel):  
  8.     def __init__(self, parent, id):  
  9.         wx.Panel.__init__(self, parent, id)  
  10.         try:  
  11.             image_file = 'image.jpg'  
  12.             to_bmp_image = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()  
  13.             self.bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))  
  14.             image_width = to_bmp_image.GetWidth()  
  15.             image_height = to_bmp_image.GetHeight()  
  16.             set_title = '%s %d x %d' % (image_file, to_bmp_image.GetWidth(), to_bmp_image.GetHeight())  
  17.             parent.SetTitle(set_title)  
  18.         except IOError:  
  19.             print 'Image file %s not found' % image_file  
  20.             raise SystemExit  
  21.         #创建一个按钮  
  22.         self.button = wx.Button(self.bitmap, -1, label='Test', pos=(10,10))  
  23. if __name__ == '__main__':  
  24.     app = wx.PySimpleApp()  
  25.     frame = wx.Frame(None, -1, 'Image', size=(300,300))  
  26.     my_panel = MyPanel(frame, -1)  
  27.     frame.Show()  
  28.     app.MainLoop()  


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多