Kivy 中的 PushMatrix 和 PopMatrix
PushMatrix and PopMatrix in Kivy
我希望第二行是原始颜色(白色)。我知道我可以写 'color: 1,1,1,1' 但我想使用 PushMatrix 和 PopMatrix 但它不起作用。 PushMatrix 和 PopMatrix 放在哪里?
这里是我的示例代码:
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
Builder.load_string("""
<GridLayout>:
cols: 2
Label:
PushMatrix:
color: 1,0,0,1
canvas:
Line:
points: self.x, self.y, self.x + self.width, self.y + self.height
PopMatrix:
Widget:
canvas:
Line:
points: self.x, self.y, self.x + self.width, self.y + self.height
""")
class LabelApp(App):
def build(self):
return GridLayout()
if __name__ == '__main__':
LabelApp().run()
Color 不是 Matrix 指令,因此 PushMatrix 和 PopMatrix 不影响它。简单的解决方案是简单地使用第二个 Color 指令。
此外,您的语法无效 - PushMatrix 和 PopMatrix 是 canvas 只能出现在 kv.canvas 部分下的指令。
编辑:明确地说,颜色是您需要添加的另一个 canvas 指令,例如
Color:
rgba: 1, 0, 0, 1
我希望第二行是原始颜色(白色)。我知道我可以写 'color: 1,1,1,1' 但我想使用 PushMatrix 和 PopMatrix 但它不起作用。 PushMatrix 和 PopMatrix 放在哪里?
这里是我的示例代码:
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
Builder.load_string("""
<GridLayout>:
cols: 2
Label:
PushMatrix:
color: 1,0,0,1
canvas:
Line:
points: self.x, self.y, self.x + self.width, self.y + self.height
PopMatrix:
Widget:
canvas:
Line:
points: self.x, self.y, self.x + self.width, self.y + self.height
""")
class LabelApp(App):
def build(self):
return GridLayout()
if __name__ == '__main__':
LabelApp().run()
Color 不是 Matrix 指令,因此 PushMatrix 和 PopMatrix 不影响它。简单的解决方案是简单地使用第二个 Color 指令。
此外,您的语法无效 - PushMatrix 和 PopMatrix 是 canvas 只能出现在 kv.canvas 部分下的指令。
编辑:明确地说,颜色是您需要添加的另一个 canvas 指令,例如
Color:
rgba: 1, 0, 0, 1