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

相关文章

pytorch+lstm实现的pos示例

学了几天终于大概明白pytorch怎么用了 这个是直接搬运的官方文档的代码 之后会自己试着实现其他nlp的任务 # Author: Robert Guthrie import to...

python中文乱码的解决方法

乱码原因: 源码文件的编码格式为utf-8,但是window的本地默认编码是gbk,所以在控制台直接打印utf-8的字符串当然是乱码了! 解决方法: 1、print mystr.deco...

Python 调用 Windows API COM 新法

Python中调用Win32API 通常都是使用 PyWin32或者ctypes。但要么依赖文件较多,要么用法繁琐。 这里介绍在Python中调用Win32 API 或者COM组件的另一...

python抖音表白程序源代码

本文实例为大家分享了python抖音表白程序的具体代码,供大家参考,具体内容如下 import sys import random import pygame from pygame...

NumPy 如何生成多维数组的方法

Python现在是最热门的人工智能语言,各种工具的支持如Google的Tensorflow,都是首选支持Python的。 但是,与R语言不同,Python语言设计时,并没有考虑对于矩阵...