python - Kivy 中的 PushMatrix 和 PopMatrix

标签 python 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 不会影响它。简单的解决方案是简单地使用第二个颜色指令。

此外,您的语法无效 - PushMatrix 和 PopMatrix 是 Canvas 指令,只能出现在 kv 的 Canvas 部分下。

编辑:要清楚,颜色是您需要添加的另一个 Canvas 指令,例如

Color:
    rgba: 1, 0, 0, 1

关于python - Kivy 中的 PushMatrix 和 PopMatrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30667613/

相关文章:

python 字典/json 初始

python - Kivy Filechooser 在屏幕上滚动重叠文本

带约束的 Python 曲线拟合

python - 如何使用 django-rest-framework 在序列化器级别扩展模型

python - 如何在 Cython 中定义 C++ 模板函数类型?

python - 无法在 Kivy 中设置布局大小

python - 有没有一种简单的方法可以在没有图像的情况下为 Kivy 标签、按钮、小部件等添加边框?

python - 在 Kivy 中创建全局变量

python - kivy按钮文本=""逻辑错误

python - 如何在 Kivy 中的 AsyncImage 中检测图片下载结束?