gpt4 book ai didi

wxpython - 如何在wxpython中将图像作为背景

转载 作者:行者123 更新时间:2023-12-02 21:37:50 28 4
gpt4 key购买 nike

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

代码:

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()

最佳答案

来自 The Mouse vs. The Python 的更正示例.

import wx

########################################################################
class MainPanel(wx.Panel):
""""""

#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
self.SetBackgroundStyle(wx.BG_STYLE_PAINT) # Was wx.BG_STYLE_CUSTOM)
self.frame = parent

sizer = wx.BoxSizer(wx.VERTICAL)
hSizer = wx.BoxSizer(wx.HORIZONTAL)

for num in range(4):
label = "Button %s" % num
btn = wx.Button(self, label=label)
sizer.Add(btn, 0, wx.ALL, 5)
hSizer.Add((1,1), 1, wx.EXPAND)
hSizer.Add(sizer, 0, wx.TOP, 100)
hSizer.Add((1,1), 0, wx.ALL, 75)
self.SetSizer(hSizer)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

#----------------------------------------------------------------------
def OnEraseBackground(self, evt):
"""
Add a picture to the background
"""
# yanked from ColourDB.py
dc = evt.GetDC()

if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
bmp = wx.Bitmap("butterfly.jpg")
dc.DrawBitmap(bmp, 0, 0)


########################################################################
class MainFrame(wx.Frame):
""""""

#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, size=(600,450))
panel = MainPanel(self)
self.Center()

########################################################################
class Main(wx.App):
""""""

#----------------------------------------------------------------------
def __init__(self, redirect=False, filename=None):
"""Constructor"""
wx.App.__init__(self, redirect, filename)
dlg = MainFrame()
dlg.Show()

#----------------------------------------------------------------------
if __name__ == "__main__":
app = Main()
app.MainLoop()

关于wxpython - 如何在wxpython中将图像作为背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18341867/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com