Python reportlab库之Label(含demo)

Label是附加图标元的文本字符串。Label可以包含换行符,但只能有一种字体。下面的demo中,一个Label可以相对于绿色球进行定义。目前Label有如下的属性:

label的属性

label的属性

Label demo

from reportlab.graphics import shapes
from reportlab.graphics.charts.textlabels import Label
d = Drawing(200, 100)
# mark the origin of the label
d.add(Circle(100,90, 5, fillColor=colors.green))
lab = Label()
lab.setOrigin(100,90)
lab.boxAnchor = 'ne'
lab.angle = 45
lab.dx = 0
lab.dy = -20
lab.boxStrokeColor = colors.green
lab.setText('Some Multi-Line Label')
d.add(lab)
from reportlab.graphics import renderPDF
renderPDF.drawToFile(d, 'label_demo.pdf', 'My First Drawing')

效果图


labdel

你可能感兴趣的:(Python reportlab库之Label(含demo))