我可以使用RichTextctrl WriteTable方法在RichTextctrl上写一个表。
def AddTable( self, event ):
self.table=self.rtc.WriteTable(3,4)图片来源:Table_Picture
但是,无法设置表格和单元格属性,也无法识别RichTextctrl中选定的单元格或表格。关于这一点的任何例子都是预先的helpful.Thanks。
wxPython 4.0.0a1(Alpha版本)
发布于 2018-07-13 01:35:54
具有相同的问题;但是在一些示例代码中,您必须让您的函数返回self.table具有的表对象
import wx
import wx.richtext as rtc假设您是在一个类中执行此操作
columncount = self.table.GetColumnCount()
rowcount = self.table.GetRowCount()要在此处获取特定的单元格,2,3
self.myCell = self.table.GetCell(row=2, col=2)现在,要写入该单元格,->必须是一个字符串
self.myCell.AddParagraph("new stuff goest here")并从表格单元格中获取文本;为所需的文本行编制索引
self.myCellText = self.myCell.GetParagraphText(0)发布于 2021-03-26 05:30:00
def create_table(自身):
xlist = []
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
xlist.append({'desc': 'blabla blabla', 'amt': 5, 'prc': 2.50})
table = self.ctrl.WriteTable(len(xlist), 3)
for pos, cont in enumerate(xlist):
# Description
cell = table.GetCell(row=pos, col=0)
prg = cell.GetParagraphAtLine(0)
prg.InsertText(1, str(cont['desc']))
prg.SetAttributes(self.set_alignment(prg, "left"))
cell.SetBasicStyle(self.set_colwidth(cell, 460))
cell.UpdateRanges()
# Amount
cell = table.GetCell(row=pos, col=1)
prg = cell.GetParagraphAtLine(0)
prg.InsertText(1, str(cont['amt']))
prg.SetAttributes(self.set_alignment(prg, "right"))
cell.SetBasicStyle(self.set_colwidth(cell, 40))
cell.UpdateRanges()
# Price
cell = table.GetCell(row=pos, col=2)
prg = cell.GetParagraphAtLine(0)
prg.InsertText(1, str(cont['prc']))
prg.SetAttributes(self.set_alignment(prg, "right"))
cell.SetBasicStyle(self.set_colwidth(cell, 60))
cell.UpdateRanges()定义宽度(set_colwidth,self,cell,width):
dim_atr = rt.TextAttrDimension()
dim_atr.SetValue(width)
dim_atr.SetUnits(rt.TEXT_ATTR_UNITS_PIXELS)
size_atr = rt.TextAttrSize()
size_atr.SetWidth(dim_atr)
box_atr = rt.TextBoxAttr()
box_atr.SetSize(size_atr)
cell_atr = cell.GetBasicStyle()
cell_atr.SetTextBoxAttr(box_atr)
return cell_atrdef set_alignment(自身、生产、或订单):
attr = prg.GetAttributes()
if ori == "left":
attr.SetAlignment(wx.TEXT_ALIGNMENT_LEFT)
attr.SetLeftIndent(16)
elif ori == "right":
attr.SetAlignment(wx.TEXT_ALIGNMENT_RIGHT)
attr.SetRightIndent(16)
return attrhttps://stackoverflow.com/questions/45193536
复制相似问题