wxpython的ListCtrl每行下面怎么用横线隔开
时间: 2023-07-08 20:55:54 浏览: 45
您可以使用`wx.ListCtrl`的`SetWindowStyleFlag`方法来设置`wx.LC_HRULES`和`wx.LC_VRULES`风格标志,以在每个单元格的下方和右侧添加水平和垂直线条。例如:
```python
import wx
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="ListCtrl with Grid Lines")
# Create a ListCtrl object
self.list_ctrl = wx.ListCtrl(self, style=wx.LC_REPORT)
# Add columns to the ListCtrl
self.list_ctrl.InsertColumn(0, "Column 1")
self.list_ctrl.InsertColumn(1, "Column 2")
# Add items to the ListCtrl
self.list_ctrl.InsertItem(0, "Item 1")
self.list_ctrl.SetItem(0, 1, "Value 1")
self.list_ctrl.InsertItem(1, "Item 2")
self.list_ctrl.SetItem(1, 1, "Value 2")
# Set the ListCtrl style flags to show horizontal and vertical grid lines
self.list_ctrl.SetWindowStyleFlag(wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES)
# Set the size of the ListCtrl
self.list_ctrl.SetSize((300, 100))
# Set the layout of the frame
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 1, wx.EXPAND)
self.SetSizer(sizer)
if __name__ == "__main__":
app = wx.App()
frame = MyFrame()
frame.Show()
app.MainLoop()
```
在上面的示例中,我们创建了一个`wx.ListCtrl`对象,并添加了一些列和行。然后,我们使用`SetWindowStyleFlag`方法设置了`wx.LC_HRULES`和`wx.LC_VRULES`风格标志,以显示水平和垂直线条。最后,我们将`wx.ListCtrl`添加到`wx.Frame`的布局中。