wxPython实现窗口用图片做背景

yipeiwu_com5年前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将数组的元素导出到变量中(unpacking)

解决的问题 需要将数组(list)或元组(tuple)中的元素导出到N个变量中。 解决的方案 任何序列都可以通过简单的变量赋值方式将其元素分配到对应的变量中,唯一的要求就是变量的数量和...

python实现人人网登录示例分享

复制代码 代码如下:import reimport urllib2import cookielib def renren():    cj = cookie...

python读取有密码的zip压缩文件实例

python读取有密码的zip压缩文件实例

今天试了一下用zipfile模块读取有密码的zip压缩文件。 今天用winrar 5.6将一个名字为1.xlsx的excel文件打包成1.zip压缩包。采用默认的压缩算法(没有勾选传统加...

Python 根据数据模板创建shapefile的实现

废话不多说,我就直接上代码让大家看看吧! #!/usr/bin/env python # -*- coding: utf-8 -*- # @File : copyShapefile....

Pycharm2017版本设置启动时默认自动打开项目的方法

Pycharm2017版本设置启动时默认自动打开项目的方法

最新版本不同于旧版本的设置,网上检索一番方法都不适用。 新版的设置位置在“configure->setting->Appearance&Behavior->System...