Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wxpython 在wx.GridBagSizer中显示图像_Wxpython - Fatal编程技术网

Wxpython 在wx.GridBagSizer中显示图像

Wxpython 在wx.GridBagSizer中显示图像,wxpython,Wxpython,我试图在wx.GridBagSizer上显示图像 正在读取图像,如果我注释掉sizerMain,我可以看到它。添加行,但它不会显示在sizer中。有趣的是,在施胶器中为其预留了空间 有人能帮忙吗 import wx class MainWindow(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,parent, wx.ID_ANY, title, size = (1200,

我试图在wx.GridBagSizer上显示图像

正在读取图像,如果我注释掉sizerMain,我可以看到它。添加行,但它不会显示在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()

wx.StaticBitmap“img”的父级需要是面板“pnl”。不是“自我”。你的代码对我有用。使用Python279和WxPythonPhoenix(上周的构建)。