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中操作文件之read()方法的使用教程

 read()方法读取文件size个字节大小。如果读取命中获得EOF大小字节之前,那么它只能读取可用的字节。 语法 以下是read()方法的语法: fileObject.r...

Python3并发写文件与Python对比

这篇文章主要介绍了Python3并发写文件原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 使用python2在进行并发写的时候...

python 读取鼠标点击坐标的实例

读取鼠标点击坐标,包括点下去和抬起来的坐标,注意不要在命令行点,可能会出问题 import pythoncom, pyHook def onMouseEvent(event):...

OpenCV+Python--RGB转HSI的实现

OpenCV+Python--RGB转HSI的实现

cv2.cvtColor函数封装了各种颜色空间之间的转换,唯独没有RGB与HSI之间的转换,网上查来查去也只有C++或MATLAB版本的,自己要用到python里,所以就写写python...

Python对数据库操作

Windows下安装MySQL-python 下载地址:https://pypi.python.org/pypi/MySQL-python/1.2.5 安装到系统即可。 linux下...