gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:51:36 25 4
gpt4 key购买 nike

我开发了一个小型 wxPython 程序,它在 Windows 和 Ubuntu 中提供完全不同的输出(我很高兴被告知我的编程不正确,我认为这是结果——只要我们可以让它工作)

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

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

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

Ubuntu screen shot

Windows screen shot

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

也似乎是多余的

关于windows - wxPython 在 Windows 和 Ubuntu 上给出不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32060635/

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