wxPython实现窗口用图片做背景

yipeiwu_com6年前Python基础

本文实例为大家分享了wxPython实现窗口用图片做背景的具体代码,供大家参考,具体内容如下

效果图:

 

实现代码:

#!/usr/bin/env python 
# -*- encoding:utf-8 -*- 
 
import wx 
 
 
class MyPanel(wx.Panel): 
 def __init__(self, parent, id): 
  wx.Panel.__init__(self, parent, id) 
  try: 
   image_file = 'image.jpg' 
   to_bmp_image = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 
   self.bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0)) 
   image_width = to_bmp_image.GetWidth() 
   image_height = to_bmp_image.GetHeight() 
   set_title = '%s %d x %d' % (image_file, to_bmp_image.GetWidth(), to_bmp_image.GetHeight()) 
   parent.SetTitle(set_title) 
  except IOError: 
   print 'Image file %s not found' % image_file 
   raise SystemExit 
  #创建一个按钮 
  self.button = wx.Button(self.bitmap, -1, label='Test', pos=(10,10)) 
if __name__ == '__main__': 
 app = wx.PySimpleApp() 
 frame = wx.Frame(None, -1, 'Image', size=(300,300)) 
 my_panel = MyPanel(frame, -1) 
 frame.Show() 
 app.MainLoop() 

 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python日志记录模块实例及改进

python 打印对象的所有属性值: def prn_obj(obj): print '\n'.join(['%s:%s' % item for item in obj.__d...

python使用wxpython开发简单记事本的方法

python使用wxpython开发简单记事本的方法

本文实例讲述了python使用wxpython开发简单记事本的方法。分享给大家供大家参考。具体分析如下: wxPython是Python编程语言的一个GUI工具箱。他使得Python程序...

python-序列解包(对可迭代元素的快速取值方法)

一般情况下 x,y,z = 1,2,3 print("x:",x) print("y:",y) print("z:",z) #运行结果 x: 1 y: 2 z: 3 对元祖序...

Python数据可视化编程通过Matplotlib创建散点图代码示例

Python数据可视化编程通过Matplotlib创建散点图代码示例

Matplotlib简述: Matplotlib是一个用于创建出高质量图表的桌面绘图包(主要是2D方面)。该项目是由JohnHunter于2002年启动的,其目的是为Python构建一个...

python实现指定字符串补全空格的方法

本文实例讲述了python实现指定字符串补全空格的方法。分享给大家供大家参考。具体分析如下: 如果希望字符串的长度固定,给定的字符串又不够长度,我们可以通过rjust,ljust和cen...