0

我试图创建一个 10 行和 10 列的网格。我没有单独显示网格的问题,但是当我添加我的菜单栏时,它没有正确显示。我基本上是在尝试添加一个查找按钮,以便我可以在网格中找到元素。

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

2 回答 2

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()
于 2013-07-11T21:52:22.933 回答
0

将鳕鱼按南北顺序排列,因此将菜单,菜单栏和菜单项放在您的框架类中,然后跟随网格的代码

于 2013-08-25T05:48:21.470 回答