2013-07-11 56 views
0

我試圖創建一個10行10列的網格。我沒有單獨顯示網格的問題,但是當我添加我的菜單欄時,它沒有正確顯示。我基本上試圖添加一個查找按鈕,以便我可以在網格中找到這些元素。wxpython添加網格和菜單欄

import wx 
import wx.grid as gridlib 

class ScrollbarFrame(wx.Frame): 
    def __init__(self): 
      wx.Frame.__init__(self, None, wx.ID_ANY,"Grid with Popup Menu") 
      self.layout_file = {'ID':[1,5,5],'NAME':[6,12],'STATE':[13,20]} 
      print self.layout_file 
      self.OnInit() 

    def OnInit(self): 
     panel = wx.Panel(self, wx.ID_ANY) 

     vbox = wx.BoxSizer(wx.VERTICAL) 
     hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox2 = wx.BoxSizer(wx.HORIZONTAL) 

     menuBar = wx.MenuBar() 

     fileMenu = wx.Menu() 
     fileMenu.Append(wx.ID_NEW, '&New') 
     fileMenu.Append(wx.ID_OPEN, '&Open') 
     fileMenu.Append(wx.ID_SAVE, '&Save') 

     menuBar.Append(fileMenu, '&File') 

     menu = self.SetMenuBar(menuBar) 

#   hbox1.Add(menu, proportion=1) 
#   vbox.Add(hbox1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10) 
     self.grid = gridlib.Grid(panel) 
     self.grid.CreateGrid(10 ,10) 

     self.grid.SetCellValue(0,0,'(0,0)') 
     self.grid.SetCellValue(0,0,'(0,1)') 
     self.grid.SetCellValue(1,0,'(1,0)') 
     self.grid.SetCellValue(1,0,'(1,1)') 


     hbox2.Add(self.grid,1,wx.EXPAND,5) 
     vbox.Add(hbox2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10) 
     panel.SetSizer(vbox) 


if __name__ == '__main__': 

    app = wx.PySimpleApp() 
    frame = ScrollbarFrame() 
    frame.Show() 
    app.MainLoop() 

回答

0

添加菜單欄的第一個以南北向,所以就把菜單添加任何部件

import wx 
import wx.grid as gridlib 

class ScrollbarFrame(wx.Frame): 
    def __init__(self): 
      wx.Frame.__init__(self, None, wx.ID_ANY,"Grid with Popup Menu") 
      self.layout_file = {'ID':[1,5,5],'NAME':[6,12],'STATE':[13,20]} 
      print self.layout_file 
      self.OnInit() 

    def OnInit(self): 
     menuBar = wx.MenuBar() 

     fileMenu = wx.Menu() 
     fileMenu.Append(wx.ID_NEW, '&New') 
     fileMenu.Append(wx.ID_OPEN, '&Open') 
     fileMenu.Append(wx.ID_SAVE, '&Save') 

     menuBar.Append(fileMenu, '&File') 

     menu = self.SetMenuBar(menuBar) 

     panel = wx.Panel(self, wx.ID_ANY) 

     vbox = wx.BoxSizer(wx.VERTICAL) 
     hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox2 = wx.BoxSizer(wx.HORIZONTAL) 

#   hbox1.Add(menu, proportion=1) 
#   vbox.Add(hbox1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10) 
     self.grid = gridlib.Grid(panel) 
     self.grid.CreateGrid(10 ,10) 

     self.grid.SetCellValue(0,0,'(0,0)') 
     self.grid.SetCellValue(0,0,'(0,1)') 
     self.grid.SetCellValue(1,0,'(1,0)') 
     self.grid.SetCellValue(1,0,'(1,1)') 


     hbox2.Add(self.grid,1,wx.EXPAND,5) 
     vbox.Add(hbox2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10) 
     panel.SetSizer(vbox) 


if __name__ == '__main__': 

    app = wx.App() 
    frame = ScrollbarFrame() 
    frame.Show() 
    app.MainLoop() 
0

把鱈魚之前,在你 框架類菜單欄和菜單項後,再之後,網格代碼