繁体   English   中英

2行中的wxpython图像

[英]wxpython images in 2 lines

我的代码有什么问题? 我想要两行图像,但是不起作用。 我找不到错误

我认为问题出在Resize函数或Sizer中,但我无法解决,是否可以用wxpython创建图库,还是应该为此找到另一个gui?

import wx

class MyFrame2 ( wx.Frame ):

def __init__( self, parent ):
    wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
    self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

    topSizer = wx.BoxSizer(wx.VERTICAL)

    bSizer11 = wx.BoxSizer( wx.HORIZONTAL )
    bSizer12 = wx.BoxSizer( wx.HORIZONTAL )

    self.img=[]
    self.bitmap=[]

    self.count_of_img=6

    for i in range(self.count_of_img):
        self.img.append(wx.Image("D:\\Pictures\\walpaper\\_1120058.jpg", wx.BITMAP_TYPE_ANY))
        self.bitmap.append(wx.StaticBitmap( self, wx.ID_ANY, wx.BitmapFromImage(self.img[i])))
        bSizer11.Add( self.bitmap[i], 0, wx.ALL | wx.EXPAND, 5 )

    for i in range(self.count_of_img):
        self.img.append(wx.Image("D:\\Pictures\\walpaper\\_1120058.jpg", wx.BITMAP_TYPE_ANY))
        self.bitmap.append(wx.StaticBitmap( self, wx.ID_ANY, wx.BitmapFromImage(self.img[i])))
        bSizer12.Add( self.bitmap[i], 0, wx.ALL | wx.EXPAND, 5 )

    topSizer.Add(bSizer11, 0, wx.ALL|wx.EXPAND, 5)
    topSizer.Add(bSizer12, 0, wx.ALL|wx.EXPAND, 5)


    self.Bind(wx.EVT_SIZE, self.onResize)
    self.SetSizer( topSizer )

    self.Layout()
    self.Centre(wx.BOTH)

def __del__( self ):
    pass

def onResize(self, event):
    # self.Layout()
    frame_size = self.GetSize()
    frame_h = (frame_size[0]-100) / self.count_of_img
    frame_w = (frame_size[1]-100) / self.count_of_img

    img=[]

    for i in range(len(self.img)):
        img.append(self.img[i].Scale(frame_h,frame_w))
        self.bitmap[i].SetBitmap(wx.BitmapFromImage(img[i]))

    self.Refresh()
    self.Layout()

app = wx.App(0)
MyFrame2(None).Show()
app.MainLoop()

很抱歉提供错误的信息。

最好的解决方案是使用类似BitmapPanel类,该类将是wxPanel的子级。 或使用wxBitmapButton。

然后,当您要调整主机架的尺寸时,面板/按钮的尺寸也将被调整。 赶上他们的大小事件,并相应地进行。

抱歉再次造成混乱。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM