如何在wxpython中将图像作为背景 [英] how to put a image as a background in wxpython

查看:73
本文介绍了如何在wxpython中将图像作为背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将背景图片添加到panel1?有哪个命令?

How to add background image to panel1? Which command is there?

代码:

import wx
import wx
appy=wx.App()

class cg(wx.Frame) :
     def __init__(self,parent,id) :
         wx.Frame.__init__(self,parent,id,'GPA',pos=(1000,600),size=(600,400))
         #splitter = wx.SplitterWindow(self, -1)
         panel1 = wx.Panel(self)
         panel2 = wx.Panel(panel1, -1,size=(600,200),style=wx.BORDER_SUNKEN)
         panel3 = wx.Panel(panel1, -1,pos=(0,200),size=(600,200),style=wx.BORDER_SUNKEN)
         #panel3=wx.panel(panel1,-1,pos=(300,200),size=(600,200),style=wx.BORDER_SUNKEN)
         #panel13 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)
         #panel13 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)
         #panel13 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)

         #button1=wx.Button(panel1,label='exit',pos=(10,10),size=(10,10))
         #self.cnt1=wx.TextCtrl(panel1,pos=(40,60),size=(120,30))

if __name__=='__main__' :

     app=wx.PySimpleApp()
     frame=cg(parent=None,id=-1)
     frame.Show()
     app.MainLoop()

推荐答案

一个简单的搜索就会让你从 鼠标与 Python.

A simple search would have brought you to this answer from The Mouse vs. The Python.

# create a background image on a wxPython panel
# and show a button on top of the image

import wx

class Panel1(wx.Panel):
    """class Panel1 creates a panel with an image on it, inherits wx.Panel"""
    def __init__(self, parent, id):
        # create the panel
        wx.Panel.__init__(self, parent, id)
        try:
            # pick an image file you have in the working folder
            # you can load .jpg  .png  .bmp  or .gif files
            image_file = 'roses.jpg'
            bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
            # image's upper left corner anchors at panel coordinates (0, 0)
            self.bitmap1 = wx.StaticBitmap(self, -1, bmp1, (0, 0))
            # show some image details
            str1 = "%s  %dx%d" % (image_file, bmp1.GetWidth(), bmp1.GetHeight()) 
            parent.SetTitle(str1)
        except IOError:
            print "Image file %s not found" % imageFile
            raise SystemExit

        # button goes on the image --> self.bitmap1 is the parent
        self.button1 = wx.Button(self.bitmap1, id=-1, label='Button1', pos=(8, 8))

app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID
# change the size of the frame to fit the backgound images
frame1 = wx.Frame(None, -1, "An image on a panel", size=(350, 400))
# create the class instance
panel1 = Panel1(frame1, -1)
frame1.Show(True)
app.MainLoop()

这篇关于如何在wxpython中将图像作为背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆