How add already captured screenshot to wx.BoxSizer?

一世执手 提交于 2019-12-25 04:51:19

问题


My Python code:

    self.images = wx.StaticBitmap(self, id=-1, pos=wx.DefaultPosition,
                            size=(200,150),
                            style= wx.SUNKEN_BORDER)
    self.hbox = wx.BoxSizer(wx.HORIZONTAL)
    self.sizer.Add(self.hbox) # my main sizer

    #in function dynamically captured images
    bmp = wx.BitmapFromImage(image)
    self.images.SetBitmap(bmp)
    self.hbox.Add(self.images, 1, wx.EXPAND | wx.ALL, 3)

...and after I want to add next image (another - I don't want to replace older) I have information "Adding a window to the same sizer twice?"

How can I resolve this problem?


回答1:


In your function for dynamically captured images, you need to create a new staticBitmap rather than setting self.images which overwrites and therefore replaces...

So instead of

self.images.SetBitmap(bmp)

you need to do

newImage = wx.StaticBitmap(self, id=-1
                           size=(200,150),
                           style= wx.SUNKEN_BORDER
                           bitmap = bmp)


self.hbox.Add(newImage, 1, wx.EXPAND | wx.ALL, 3)
self.SetSizerAndFit(self.sizer)
self.Refresh()
self.Layout()


来源:https://stackoverflow.com/questions/3566528/how-add-already-captured-screenshot-to-wx-boxsizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!