我正在尝试在wx.GridBagSizer上显示图像
正在读取图像,如果我注释掉sizerMain.Add行,我可以看到它,但它不会显示在sizer中。有趣的是,空间是在sizer中保留的。
有人可以帮忙吗?
import wx
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent, wx.ID_ANY, title, size = (1200,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
sizerMain = wx.GridBagSizer(3, 2)
self.sizerMain = sizerMain
pnl = wx.Panel(self)
cmd1 = wx.Button(pnl, label='aaaaa')
cmd2 = wx.Button(pnl, label='bbbbbb')
cmd3 = wx.Button(pnl, label='ccccc')
cmd4 = wx.Button(pnl, label='dddd')
imgSizer = wx.BoxSizer(wx.HORIZONTAL)
image = wx.Bitmap('test.png',wx.BITMAP_TYPE_PNG)
img = wx.StaticBitmap(self, -1, image)
imgSizer.Add(img, flag=wx.LEFT, border=10)
sizerMain.Add(imgSizer, pos=(0,0), span=(1, 3), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=10)
sizerMain.Add(cmd1, pos=(2,2), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=10)
sizerMain.Add(cmd2, pos=(1, 0), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=10)
sizerMain.Add(cmd3, pos=(1, 1), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=10)
sizerMain.Add(cmd4, pos=(2, 1), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=10)
pnl.SetSizer(sizerMain)
pnl.Layout()
pnl.Fit()
self.Show(True)
def CloseWindow(self, event):
self.Close()
class MyApp(wx.App):
def OnInit(self):
frame = MainWindow(None, -1, "Test GridBag")
frame.Centre()
self.SetTopWindow(frame)
return True
# Declare the Application and start the Main Loop
app = MyApp(0)
app.MainLoop()
答案 0 :(得分:0)
wx.StaticBitmap的父级" img"需要成为小组" pnl"。不是"自我"。