wxPython在Windows和Ubuntu上给出了不同的结果

我已经开发了一个小的wxPython程序,它在WindowsUbuntu中给出了完全不同的输出(我很高兴被告知我已经错误地编程了,所以我会认为这是一个结果 – 只要我们能够使它工作)

该程序右侧显示四个形状。 双击右侧的图像将它们移动到左侧,反之亦然。

Windows上的问题(请参阅在Windows和Ubuntu中执行相同操作之后拍摄的屏幕截图):button无法正确呈现; 当我点击十字,圆柱或正方形时,它们正确地移动到屏幕的左侧,但三angular形的多个图像仍然保留; 一个图像出现在左上angular

这些问题都没有出现在Ubuntu中

Ubuntu屏幕截图

Windows屏幕截图

import wx class ImageSizer(wx.Frame): def __init__(self, parent, title): super(ImageSizer, self).__init__(parent, title=title, size=(250, 200)) self.ShapeTypes=['available','selected'] self.MainSizer=wx.GridBagSizer() self.SetSizer(self.MainSizer) cmdNew=wx.Button(self, label='New') cmdNew.Bind(wx.EVT_BUTTON, self.onNewClick) cmdCancel=wx.Button(self, label='Cancel') cmdCancel.Bind(wx.EVT_BUTTON, self.CancelClick) self.MainSizer.Add((500,0), pos=(0,0), span=(1,2)) #dummy to position Available self.MainSizer.Add((0,200), pos=(1,0), span=(1,1)) #dummy to position Buttons self.MainSizer.Add(cmdNew, pos=(2,2), flag=wx.LEFT|wx.TOP, border=10) self.MainSizer.Add(cmdCancel, pos=(2,3), flag=wx.RIGHT|wx.BOTTOM|wx.TOP|wx.ALIGN_RIGHT, border=10) self.SetBackgroundColour((246, 244, 242)) self.Initialise() self.Center() self.Fit() self.Show() def DisplayImages(self): availableSizer=ShapeSizer(self, self.AvailableShapes, self.ShapeTypes.index('available')) self.RefreshSizerCell(self.MainSizer, availableSizer, (1,2), (1,2)) selectedSizer=ShapeSizer(self, self.SelectedShapes, self.ShapeTypes.index('selected')) self.RefreshSizerCell(self.MainSizer, selectedSizer, (1,1), (1,1)) def Initialise(self): self.AvailableShapes=['square','circle','triangle','cross'] self.SelectedShapes=[] self.DisplayImages() def RefreshSizerCell(self, sizer, item, pos, span, flag=wx.ALL, border=10): self.Freeze() oldItem=sizer.FindItemAtPosition(pos) if (oldItem !=None) and oldItem.IsWindow(): oldItem.GetWindow().Destroy() sizer.Add(item, pos=pos, span=span, flag=flag, border=border) self.Layout() self.Thaw() def GetShapeName(self, event): imgCtrl=event.GetEventObject() return imgCtrl.GetName() def onAvailableShapeDClick(self, event): shape=self.GetShapeName(event) self.AvailableShapes.remove(shape) self.SelectedShapes.append(shape) self.DisplayImages() def onSelectedShapeDClick(self, event): shape=self.GetShapeName(event) self.SelectedShapes.remove(shape) self.AvailableShapes.append(shape) self.DisplayImages() def onNewClick(self, event): self.Initialise() def CancelClick(self, event): self.Destroy() class ShapeSizer(wx.Panel): def __init__(self, frame, shapes, shapeType): wx.Panel.__init__(self, frame, id=wx.ID_ANY) if shapeType==frame.ShapeTypes.index('available'): size=40 action=frame.onAvailableShapeDClick elif shapeType==frame.ShapeTypes.index('selected'): size=80 action=frame.onSelectedShapeDClick shapeSizer=wx.GridBagSizer() shapes.sort() for ii in range(0, len(shapes)): bitmap=wx.Bitmap(shapes[ii]+'.png',wx.BITMAP_TYPE_PNG) bitmap=self.ScaleBitmap(bitmap, size, size) img=wx.StaticBitmap(self, wx.ID_ANY, bitmap, name=shapes[ii]) img.Bind(wx.EVT_LEFT_DCLICK, action) shapeSizer.Add(img, pos=(0,ii), flag=wx.RIGHT, border=10) self.SetSizer(shapeSizer) def ScaleBitmap(self, bitmap, width, height): image = wx.ImageFromBitmap(bitmap) image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH) result = wx.BitmapFromImage(image) return result if __name__ == '__main__': app = wx.App() ImageSizer(None, title='Image Sizer') app.MainLoop() 

triangle.png

square.png

circle.png

cross.png

这里的问题是线条

 self.Freeze() 

 self.Thaw() 

 RefreshSizerCell() 

在Windows中似乎没有任何用处:(

该线

 Self.Layout() 

也似乎是多余的