使用python';s wx.grid,如何合并列?
这是我到目前为止创建的表 下面是我希望它的样子,合并了列 我想把昨天和今天的专栏合并成三个专栏。因此,昨日将高于股本、波动性和现金。那么今天也是这样。我发现了一个名为使用python';s wx.grid,如何合并列?,python,wxpython,wxwidgets,Python,Wxpython,Wxwidgets,这是我到目前为止创建的表 下面是我希望它的样子,合并了列 我想把昨天和今天的专栏合并成三个专栏。因此,昨日将高于股本、波动性和现金。那么今天也是这样。我发现了一个名为wx.grid.SetColSize(self,int col,int width)的函数,但它没有任何效果。有人知道怎么做吗 这也是我的代码 import wx import wx.grid as gridlib class MyForm(wx.Frame): def __init__(self):
wx.grid.SetColSize(self,int col,int width)
的函数,但它没有任何效果。有人知道怎么做吗
这也是我的代码
import wx
import wx.grid as gridlib
class MyForm(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="Strategies' Allocations")
self.panel = wx.Panel(self)
button_refresh = wx.Button(self.panel, id=wx.ID_ANY, label='Refresh')
button_refresh.Bind(wx.EVT_BUTTON, self.refresh)
self.myGrid1 = gridlib.Grid(self.panel)
self.myGrid1.CreateGrid(2, 6)
self.myGrid1.SetRowLabelSize(60)
self.myGrid1.SetRowLabelValue(0, "")
self.myGrid1.SetRowLabelValue(1, "ABRVXX")
for i in range(6):
self.myGrid1.SetColSize(i, 60)
self.myGrid1.SetColLabelValue(0, "")
self.myGrid1.SetColLabelValue(1, "Yesterday")
self.myGrid1.SetColLabelValue(2, "")
self.myGrid1.SetColLabelValue(3, "")
self.myGrid1.SetColLabelValue(4, "Today")
self.myGrid1.SetColLabelValue(5, "")
self.myGrid1.SetCellValue(0, 0, "Equity")
self.myGrid1.SetCellValue(0, 1, "Volatility")
self.myGrid1.SetCellValue(0, 2, "Cash")
self.myGrid1.SetCellValue(0, 3, "Equity")
self.myGrid1.SetCellValue(0, 4, "Volatility")
self.myGrid1.SetCellValue(0, 5, "Cash")
self.myGrid1.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
self.myGrid1.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
# ******************************* #
self.myGrid2 = gridlib.Grid(self.panel)
self.myGrid2.CreateGrid(2, 6)
for i in range(6):
self.myGrid2.SetColSize(i, 60)
self.myGrid2.SetColLabelValue(0, "")
self.myGrid2.SetColLabelValue(1, "Yesterday")
self.myGrid2.SetColLabelValue(2, "")
self.myGrid2.SetColLabelValue(3, "")
self.myGrid2.SetColLabelValue(4, "Today")
self.myGrid2.SetColLabelValue(5, "")
self.myGrid2.SetCellValue(0, 0, "Treasury")
self.myGrid2.SetCellValue(0, 1, "Volatility")
self.myGrid2.SetCellValue(0, 2, "Cash")
self.myGrid2.SetCellValue(0, 3, "Treasury")
self.myGrid2.SetCellValue(0, 4, "Volatility")
self.myGrid2.SetCellValue(0, 5, "Cash")
self.myGrid2.SetRowLabelSize(60)
self.myGrid2.SetRowLabelValue(0, "")
self.myGrid2.SetRowLabelValue(1, "ABRXIV")
self.myGrid2.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
self.myGrid2.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
# ****************************** #
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.myGrid1, 1, wx.TOP|wx.ALIGN_CENTRE, 2)
sizer.Add(self.myGrid2, 1, wx.TOP|wx.ALIGN_CENTRE, 2)
sizer.Add(button_refresh, 1, wx.RIGHT|wx.LEFT|wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ALIGN_CENTRE, 50)
self.panel.SetSizer(sizer)
self.panel.SetSize((500,400))
self.SetSize((500,400))
self.panel.Layout()
def refresh(self, event):
pass
if __name__ == "__main__":
app = wx.App()
frame = MyForm().Show()
app.MainLoop()
这并不是特别简单,但我认为您应该通过定义一个派生自
wxGridCellAttrProvider
的类并重写其GetColumnHeaderRenderer()
方法以返回“不做任何事情”来实现您想要的wxGridColumnHeaderRenderer
用于要合并的列,标准呈现程序(由基类GetColumnHeaderRenderer()
返回)用于其他列。然后,您只需要使用表对象上的自定义属性提供程序对象调用SetAttrProvider()
。这并不是特别简单,但我认为您应该通过定义一个派生自wxGridCellAttrProvider
的类并重写它的GetColumnHeaderRenderer()来实现您想要的目标
方法为要合并的列返回“不做任何事”wxGridColumnHeaderRenderer
,为其他列返回标准呈现程序(由基类GetColumnHeaderRenderer()
返回)。然后,您只需使用表对象上的自定义属性提供程序对象调用SetAttrProvider()
。一种快速而肮脏的方法是转储列标签SetColLabelSize(0)
,并将标题添加为单元格。然后仅为那些具有
SetCellSize()
的单元格调整单元格范围下面我修改了myGrid1,但没有修改myGrid2
import wx
import wx.grid as gridlib
class MyForm(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="Strategies' Allocations")
self.panel = wx.Panel(self)
button_refresh = wx.Button(self.panel, id=wx.ID_ANY, label='Refresh')
button_refresh.Bind(wx.EVT_BUTTON, self.refresh)
self.myGrid1 = gridlib.Grid(self.panel)
self.myGrid1.CreateGrid(3, 6)
self.myGrid1.SetRowLabelSize(80)
self.myGrid1.SetRowLabelValue(0, "")
self.myGrid1.SetRowLabelValue(1, "")
self.myGrid1.SetRowLabelValue(2, "2")
for i in range(6):
self.myGrid1.SetColSize(i, 60)
# self.myGrid1.SetColLabelValue(0, "")
# self.myGrid1.SetColLabelValue(1, "Yesterday")
# self.myGrid1.SetColLabelValue(2, "")
# self.myGrid1.SetColLabelValue(3, "")
# self.myGrid1.SetColLabelValue(4, "Today")
# self.myGrid1.SetColLabelValue(5, "")
self.myGrid1.SetColLabelSize(0)
self.myGrid1.SetCellSize(0, 0, 1, 3)
self.myGrid1.SetCellValue(0, 0, "Yesterday")
self.myGrid1.SetCellSize(0, 3, 1, 3)
self.myGrid1.SetCellValue(0, 3, "Today")
self.myGrid1.SetCellValue(1, 0, "Equity")
self.myGrid1.SetCellValue(1, 1, "Volatility")
self.myGrid1.SetCellValue(1, 2, "Cash")
self.myGrid1.SetCellValue(1, 3, "Equity")
self.myGrid1.SetCellValue(1, 4, "Volatility")
self.myGrid1.SetCellValue(1, 5, "Cash")
self.myGrid1.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
self.myGrid1.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
# ******************************* #
self.myGrid2 = gridlib.Grid(self.panel)
self.myGrid2.CreateGrid(2, 6)
for i in range(6):
self.myGrid2.SetColSize(i, 60)
self.myGrid2.SetColLabelValue(0, "")
self.myGrid2.SetColLabelValue(1, "Yesterday")
self.myGrid2.SetColLabelValue(2, "")
self.myGrid2.SetColLabelValue(3, "")
self.myGrid2.SetColLabelValue(4, "Today")
self.myGrid2.SetColLabelValue(5, "")
self.myGrid2.SetCellValue(0, 0, "Treasury")
self.myGrid2.SetCellValue(0, 1, "Volatility")
self.myGrid2.SetCellValue(0, 2, "Cash")
self.myGrid2.SetCellValue(0, 3, "Treasury")
self.myGrid2.SetCellValue(0, 4, "Volatility")
self.myGrid2.SetCellValue(0, 5, "Cash")
self.myGrid2.SetRowLabelSize(60)
self.myGrid2.SetRowLabelValue(0, "")
self.myGrid2.SetRowLabelValue(1, "2")
self.myGrid2.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
self.myGrid2.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
# ****************************** #
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.myGrid1, 1, wx.TOP|wx.ALIGN_CENTRE, 2)
sizer.Add(self.myGrid2, 1, wx.TOP|wx.ALIGN_CENTRE, 2)
sizer.Add(button_refresh, 1, wx.RIGHT|wx.LEFT|wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ALIGN_CENTRE, 50)
self.panel.SetSizer(sizer)
self.panel.SetSize((500,400))
self.SetSize((500,400))
self.panel.Layout()
def refresh(self, event):
pass
if __name__ == "__main__":
app = wx.App()
frame = MyForm().Show()
app.MainLoop()
一种快速而肮脏的方法是转储列标签
SetColLabelSize(0)
并将标题添加为单元格。然后仅为那些具有
SetCellSize()
的单元格调整单元格范围下面我修改了myGrid1,但没有修改myGrid2
import wx
import wx.grid as gridlib
class MyForm(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="Strategies' Allocations")
self.panel = wx.Panel(self)
button_refresh = wx.Button(self.panel, id=wx.ID_ANY, label='Refresh')
button_refresh.Bind(wx.EVT_BUTTON, self.refresh)
self.myGrid1 = gridlib.Grid(self.panel)
self.myGrid1.CreateGrid(3, 6)
self.myGrid1.SetRowLabelSize(80)
self.myGrid1.SetRowLabelValue(0, "")
self.myGrid1.SetRowLabelValue(1, "")
self.myGrid1.SetRowLabelValue(2, "2")
for i in range(6):
self.myGrid1.SetColSize(i, 60)
# self.myGrid1.SetColLabelValue(0, "")
# self.myGrid1.SetColLabelValue(1, "Yesterday")
# self.myGrid1.SetColLabelValue(2, "")
# self.myGrid1.SetColLabelValue(3, "")
# self.myGrid1.SetColLabelValue(4, "Today")
# self.myGrid1.SetColLabelValue(5, "")
self.myGrid1.SetColLabelSize(0)
self.myGrid1.SetCellSize(0, 0, 1, 3)
self.myGrid1.SetCellValue(0, 0, "Yesterday")
self.myGrid1.SetCellSize(0, 3, 1, 3)
self.myGrid1.SetCellValue(0, 3, "Today")
self.myGrid1.SetCellValue(1, 0, "Equity")
self.myGrid1.SetCellValue(1, 1, "Volatility")
self.myGrid1.SetCellValue(1, 2, "Cash")
self.myGrid1.SetCellValue(1, 3, "Equity")
self.myGrid1.SetCellValue(1, 4, "Volatility")
self.myGrid1.SetCellValue(1, 5, "Cash")
self.myGrid1.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
self.myGrid1.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
# ******************************* #
self.myGrid2 = gridlib.Grid(self.panel)
self.myGrid2.CreateGrid(2, 6)
for i in range(6):
self.myGrid2.SetColSize(i, 60)
self.myGrid2.SetColLabelValue(0, "")
self.myGrid2.SetColLabelValue(1, "Yesterday")
self.myGrid2.SetColLabelValue(2, "")
self.myGrid2.SetColLabelValue(3, "")
self.myGrid2.SetColLabelValue(4, "Today")
self.myGrid2.SetColLabelValue(5, "")
self.myGrid2.SetCellValue(0, 0, "Treasury")
self.myGrid2.SetCellValue(0, 1, "Volatility")
self.myGrid2.SetCellValue(0, 2, "Cash")
self.myGrid2.SetCellValue(0, 3, "Treasury")
self.myGrid2.SetCellValue(0, 4, "Volatility")
self.myGrid2.SetCellValue(0, 5, "Cash")
self.myGrid2.SetRowLabelSize(60)
self.myGrid2.SetRowLabelValue(0, "")
self.myGrid2.SetRowLabelValue(1, "2")
self.myGrid2.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
self.myGrid2.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
# ****************************** #
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.myGrid1, 1, wx.TOP|wx.ALIGN_CENTRE, 2)
sizer.Add(self.myGrid2, 1, wx.TOP|wx.ALIGN_CENTRE, 2)
sizer.Add(button_refresh, 1, wx.RIGHT|wx.LEFT|wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ALIGN_CENTRE, 50)
self.panel.SetSizer(sizer)
self.panel.SetSize((500,400))
self.SetSize((500,400))
self.panel.Layout()
def refresh(self, event):
pass
if __name__ == "__main__":
app = wx.App()
frame = MyForm().Show()
app.MainLoop()
看看wxPython演示中的GridLabelRenderer示例。这是一个基于
wx.lib.mixins.gridlabelrenderer
中的类为网格行和列绘制自定义标签的示例。使用这些类,您可以很容易地按照自己的意愿绘制标签。您只需要覆盖适当的绘制方法。看看wxPython演示中的GridLabelRenderer示例。这是一个基于wx.lib.mixins.gridlabelrenderer
中的类为网格行和列绘制自定义标签的示例。使用这些类,您可以很容易地按照自己的意愿绘制标签。您只需要覆盖适当的绘制方法。正如@RobinDunn所建议的,这里有一个使用GridLabelRenderer
的版本(排序),它不像最初看起来那么复杂。然而,它确实有一两个怪癖。
注意使用
l
和r
来存储rect.left
和rect.right
这样做是因为,如果您调整
rect.left
,right.right
也会调整,而无需您要求。我假设这是因为
rect
有一个大小,因此如果您调整一个元素,另一个元素将进行补偿。还要注意,您必须声明空白列标题,否则它们将返回到标准的“A、B、C、D…”序列。
import wx
import wx.grid as grid
import wx.lib.mixins.gridlabelrenderer as glr
#----------------------------------------------------------------------
class MyGrid(grid.Grid, glr.GridWithLabelRenderersMixin):
def __init__(self, *args, **kw):
grid.Grid.__init__(self, *args, **kw)
glr.GridWithLabelRenderersMixin.__init__(self)
class TextLabelRenderer(glr.GridLabelRenderer):
def __init__(self, text, colspan,bgcolour=None):
self.text = text
self.colspan = colspan
if bgcolour is not None:
self.bgcolour = bgcolour
else:
self.bgcolour = "white"
def Draw(self, grid, dc, rect, col):
if self.colspan == 0:
rect.SetSize((0,0))
if self.colspan > 1:
add_cols = self.colspan - 1
l = rect.left
r = rect.right + ((rect.Size.x -1) * add_cols)
rect.left = l
rect.right = r
dc.SetBrush(wx.Brush(self.bgcolour))
dc.SetPen(wx.TRANSPARENT_PEN)
dc.DrawRectangleRect(rect)
hAlign, vAlign = grid.GetColLabelAlignment()
text = self.text
if self.colspan != 0:
self.DrawBorder(grid, dc, rect)
self.DrawText(grid, dc, rect, text, hAlign, vAlign)
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, size=(800,300))
ROWS = 6
COLS = 11
g = MyGrid(self, size=(100,100))
g.CreateGrid(ROWS, COLS)
g.SetColLabelRenderer(0, TextLabelRenderer('Contract',1,"lightblue"))
g.SetColLabelRenderer(1, TextLabelRenderer('Yesterday',3,"lightgreen"))
g.SetColLabelRenderer(2, TextLabelRenderer('',0))
g.SetColLabelRenderer(3, TextLabelRenderer('',0))
g.SetColLabelRenderer(4, TextLabelRenderer('Today',4,"green"))
g.SetColLabelRenderer(5, TextLabelRenderer('',0))
g.SetColLabelRenderer(6, TextLabelRenderer('',0))
g.SetColLabelRenderer(7, TextLabelRenderer('',0))
g.SetColLabelRenderer(8, TextLabelRenderer('Other',1,"gold"))
# g.SetColLabelRenderer(9, TextLabelRenderer('',0))
g.SetRowLabelSize(0)
g.SetCellValue(0, 1, "Equity")
g.SetCellValue(0, 2, "Volatility")
g.SetCellValue(0, 3, "Cash")
g.SetCellValue(0, 4, "Equity")
g.SetCellValue(0, 5, "Volatility")
g.SetCellValue(0, 6, "Cash")
g.SetCellValue(1, 0, "2")
g.SetCellValue(1, 1, "1500")
g.SetCellValue(1, 2, "23")
g.SetCellValue(1, 3, "2300")
g.SetCellValue(1, 4, "1400")
g.SetCellValue(1, 5, "26")
g.SetCellValue(1, 6, "2400")
g.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
g.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
g1 = MyGrid(self, size=(100,100))
g1.CreateGrid(ROWS, COLS)
g1.SetColLabelRenderer(0, TextLabelRenderer('Contract',1,"lightblue"))
g1.SetColLabelRenderer(1, TextLabelRenderer('Yesterday',3,"lightgreen"))
g1.SetColLabelRenderer(2, TextLabelRenderer('',0))
g1.SetColLabelRenderer(3, TextLabelRenderer('',0))
g1.SetColLabelRenderer(4, TextLabelRenderer('Today',3,"green"))
g1.SetColLabelRenderer(5, TextLabelRenderer('',0))
g1.SetColLabelRenderer(6, TextLabelRenderer('',0))
g1.SetColLabelRenderer(7, TextLabelRenderer('Other',2,"gold"))
g1.SetColLabelRenderer(8, TextLabelRenderer('',0))
g1.SetRowLabelSize(0)
g1.SetCellValue(0, 1, "Equity")
g1.SetCellValue(0, 2, "Volatility")
g1.SetCellValue(0, 3, "Cash")
g1.SetCellValue(0, 4, "Equity")
g1.SetCellValue(0, 5, "Volatility")
g1.SetCellValue(0, 6, "Cash")
g1.SetCellValue(1, 0, "2")
g1.SetCellValue(1, 1, "500")
g1.SetCellValue(1, 2, "23")
g1.SetCellValue(1, 3, "12300")
g1.SetCellValue(1, 4, "11400")
g1.SetCellValue(1, 5, "26")
g1.SetCellValue(1, 6, "12400")
g1.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
g1.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
self.Sizer = wx.BoxSizer(wx.VERTICAL)
self.Sizer.Add(g, 1, wx.EXPAND)
self.Sizer.Add(g1, 1, wx.EXPAND)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App()
frame = TestPanel()
app.MainLoop()
正如@RobinDunn所建议的,这里有一个使用
GridLabelRenderer
的版本(各种各样),它不像最初看起来那么复杂。然而,它确实有一两个怪癖。
注意使用
l
和r
来存储rect.left
和rect.right
这样做是因为,如果您调整
rect.left
,right.right
也会调整,而无需您要求。我假设这是因为
rect
有一个大小,因此如果您调整一个元素,另一个元素将进行补偿。还要注意,您必须声明空白列标题,否则它们将返回到标准的“A、B、C、D…”序列。
import wx
import wx.grid as grid
import wx.lib.mixins.gridlabelrenderer as glr
#----------------------------------------------------------------------
class MyGrid(grid.Grid, glr.GridWithLabelRenderersMixin):
def __init__(self, *args, **kw):
grid.Grid.__init__(self, *args, **kw)
glr.GridWithLabelRenderersMixin.__init__(self)
class TextLabelRenderer(glr.GridLabelRenderer):
def __init__(self, text, colspan,bgcolour=None):
self.text = text
self.colspan = colspan
if bgcolour is not None:
self.bgcolour = bgcolour
else:
self.bgcolour = "white"
def Draw(self, grid, dc, rect, col):
if self.colspan == 0:
rect.SetSize((0,0))
if self.colspan > 1:
add_cols = self.colspan - 1
l = rect.left
r = rect.right + ((rect.Size.x -1) * add_cols)
rect.left = l
rect.right = r
dc.SetBrush(wx.Brush(self.bgcolour))
dc.SetPen(wx.TRANSPARENT_PEN)
dc.DrawRectangleRect(rect)
hAlign, vAlign = grid.GetColLabelAlignment()
text = self.text
if self.colspan != 0:
self.DrawBorder(grid, dc, rect)
self.DrawText(grid, dc, rect, text, hAlign, vAlign)
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, size=(800,300))
ROWS = 6
COLS = 11
g = MyGrid(self, size=(100,100))
g.CreateGrid(ROWS, COLS)
g.SetColLabelRenderer(0, TextLabelRenderer('Contract',1,"lightblue"))
g.SetColLabelRenderer(1, TextLabelRenderer('Yesterday',3,"lightgreen"))
g.SetColLabelRenderer(2, TextLabelRenderer('',0))
g.SetColLabelRenderer(3, TextLabelRenderer('',0))
g.SetColLabelRenderer(4, TextLabelRenderer('Today',4,"green"))
g.SetColLabelRenderer(5, TextLabelRenderer('',0))
g.SetColLabelRenderer(6, TextLabelRenderer('',0))
g.SetColLabelRenderer(7, TextLabelRenderer('',0))
g.SetColLabelRenderer(8, TextLabelRenderer('Other',1,"gold"))
# g.SetColLabelRenderer(9, TextLabelRenderer('',0))
g.SetRowLabelSize(0)
g.SetCellValue(0, 1, "Equity")
g.SetCellValue(0, 2, "Volatility")
g.SetCellValue(0, 3, "Cash")
g.SetCellValue(0, 4, "Equity")
g.SetCellValue(0, 5, "Volatility")
g.SetCellValue(0, 6, "Cash")
g.SetCellValue(1, 0, "2")
g.SetCellValue(1, 1, "1500")
g.SetCellValue(1, 2, "23")
g.SetCellValue(1, 3, "2300")
g.SetCellValue(1, 4, "1400")
g.SetCellValue(1, 5, "26")
g.SetCellValue(1, 6, "2400")
g.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
g.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
g1 = MyGrid(self, size=(100,100))
g1.CreateGrid(ROWS, COLS)
g1.SetColLabelRenderer(0, TextLabelRenderer('Contract',1,"lightblue"))
g1.SetColLabelRenderer(1, TextLabelRenderer('Yesterday',3,"lightgreen"))
g1.SetColLabelRenderer(2, TextLabelRenderer('',0))
g1.SetColLabelRenderer(3, TextLabelRenderer('',0))
g1.SetColLabelRenderer(4, TextLabelRenderer('Today',3,"green"))
g1.SetColLabelRenderer(5, TextLabelRenderer('',0))
g1.SetColLabelRenderer(6, TextLabelRenderer('',0))
g1.SetColLabelRenderer(7, TextLabelRenderer('Other',2,"gold"))
g1.SetColLabelRenderer(8, TextLabelRenderer('',0))
g1.SetRowLabelSize(0)
g1.SetCellValue(0, 1, "Equity")
g1.SetCellValue(0, 2, "Volatility")
g1.SetCellValue(0, 3, "Cash")
g1.SetCellValue(0, 4, "Equity")
g1.SetCellValue(0, 5, "Volatility")
g1.SetCellValue(0, 6, "Cash")
g1.SetCellValue(1, 0, "2")
g1.SetCellValue(1, 1, "500")
g1.SetCellValue(1, 2, "23")
g1.SetCellValue(1, 3, "12300")
g1.SetCellValue(1, 4, "11400")
g1.SetCellValue(1, 5, "26")
g1.SetCellValue(1, 6, "12400")
g1.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
g1.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
self.Sizer = wx.BoxSizer(wx.VERTICAL)
self.Sizer.Add(g, 1, wx.EXPAND)
self.Sizer.Add(g1, 1, wx.EXPAND)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App()
frame = TestPanel()
app.MainLoop()
您提到的问题使用了wx.Grid,但对于那些不需要它的人,可以使用它。它允许项目跨越多个列和/或行。您使用wx.Grid提出的问题,但对于那些不需要此选项的人,可以改用此选项。它允许项目跨越多个列和/或行。不确定您的意思。你能给我一些屏幕截图,说明你在网格中寻找的数据吗?@Igor我添加了一个屏幕截图来显示我想要什么。不确定你的意思。你能给我一些屏幕截图,说明你在网格中寻找的数据吗?@Igor我添加了一个屏幕截图来显示我想要什么。因为我正在尝试做的事情,这就完成了工作。谢谢您的帮助。@AlexF在您对两个答案进行编辑后,我已经添加了调整后的图像。如果仍然存在隐私问题,请随时重新编辑。这很好。对那些需要它的人仍然很有帮助,但是保持了隐私。谢谢你的通融。因为我所做的,这件事完成了。谢谢您的帮助。@AlexF在您对两个答案进行编辑后,我已经添加了调整后的图像。如果仍然存在隐私问题,请随时重新编辑。这很好。对那些需要它的人仍然很有帮助,但是保持了隐私。谢谢你的通融。