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设计】。

相关文章

Pytorch中index_select() 函数的实现理解

函数形式: index_select( dim, index ) 参数: dim:表示从第几维挑选数据,类型为int值; index:表示从第一个参数维度中的哪个...

Python 进程操作之进程间通过队列共享数据,队列Queue简单示例

本文实例讲述了Python 进程操作之进程间通过队列共享数据,队列Queue。分享给大家供大家参考,具体如下: 队列中的数据是放在内存中的,可以通过分布式缓存redis优化队列。 dem...

python 求定积分和不定积分示例

python 求定积分和不定积分示例

求f(x) = sin(x)/x 的不定积分和负无穷到正无穷的定积分 sin(x)/x 的不定积分是信号函数sig ,负无穷到正无穷的定积分为pi import math impor...

Python 日期区间处理 (本周本月上周上月...)

工具类 class CalendarUtils: """ 日期工具类 """ @staticmethod def delta_day(delta=0):...

浅谈Python3中strip()、lstrip()、rstrip()用法详解

简单来说,三种方法是为了删除字符串中不同位置的指定字符。其中,strip()用于去除字符串的首尾字符,同理,lstrip()用于去除左边的字符,rstrip()用于去除右边的字符 Py...