class MyWidget(Widget):
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
with self.canvas:
# add your instruction for main canvas here
with self.canvas.before:
# you can use this to add instructions rendered before
with self.canvas.after:
# you can use this to add instructions rendered after
with self.canvas.before:
Color(1, 0, .4, mode='rgb')
绘图指令范围从非常简单的指令,如绘制直线或多边形,到更复杂的指令,如网格或贝塞尔曲线:
with self.canvas:
# draw a line using the default color
Line(points=(x1, y1, x2, y2, x3, y3))
# lets draw a semi-transparent red square
Color(1, 0, 0, .5, mode='rgba')
Rectangle(pos=self.pos, size=self.size)