当我使用wxpython创建网格时,我将顶部列标题设为“A”,“B”,“C”......
import wx
import wx.grid as gridlib
########################################################################
class MyForm(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="A Simple Grid")
panel = wx.Panel(self)
myGrid = gridlib.Grid(panel)
myGrid.CreateGrid(12, 8)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myGrid, 1, wx.EXPAND)
panel.SetSizer(sizer)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
但我想设置自定义列标题:
怎么做?
答案 0 :(得分:11)
WxPython wiki告诉每个行和列如何具有可设置的标签(标题),这些标签可以包含任何文本以及它自己的其他布局。
列标题由命令
设置SetColLabelValue(int col, const wxString& value)
将列号和所需的标签值作为参数。
This tutorial进一步表明,您案例中的完整示例代码如下:
import wx
import wx.grid as gridlib
########################################################################
class MyForm(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="A Simple Grid")
panel = wx.Panel(self)
myGrid = gridlib.Grid(panel)
myGrid.CreateGrid(12, 8)
myGrid.SetColLabelValue(0, "ID")
myGrid.SetColLabelValue(1, "Name")
myGrid.SetColLabelValue(2, "Lastname")
myGrid.SetColLabelValue(3, "01-Jan-13")
# etc. etc.
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myGrid, 1, wx.EXPAND)
panel.SetSizer(sizer)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
当然,如果该日期在飞行中初始化,那么您必须获取它,例如从datetime
对象中将这些行添加到您的代码中(取自this post):
# Add to imports
import datetime
# fetch date and you can give this, not hard coded string value.
datetime.datetime.today()
要对您的图书重复多年/次,请查看以下内容:
from dateutil import rrule
from datetime import datetime, timedelta
now = datetime.now()
tenYearsLater = now + timedelta(years=10)
for dt in rrule.rrule(rrule.DAILY, dtstart=now, until=tenYearsLater):
print dt