如何通过在根窗口小部件中使用方法来更改子窗口小部件的属性?

时间:2016-06-27 09:57:56

标签: python kivy

我正在尝试执行以下操作。

-i有#GameScreen'作为根小部件。

- 当我点击一个按钮时,如果它的颜色是红色,我希望它的颜色变为绿色。同时,我也想要'标签'的值。要增加1.我想通过在GameScreen类中使用一个方法来实现它。但是我无法做到后一部分。

请帮忙。我是kivy的新手.Below是kv代码。

<Button>:
    size_hint:0.33,0.8/3
<GameScreen>:

   Button:
        name:"1"
        text:self.name
        color:1,0,0,1
        pos_hint:{"left":0,"bottom":1}
        on_press:self.color=root.change_color(self.color)
  Button:
        name:"2"
        text:self.name
        color:0,1,0,1
        pos_hint:{"x":0.33,"bottom":1}
        on_press:self.color=root.change_color(self.color)
  Label:
        id:my_score
        size_hint:0.2,0.2
        pos_hint:{"x":0.4,"y":0.8}
        text:"78"

1 个答案:

答案 0 :(得分:1)

您可以使用kv语言中的三元运算符,并使用&#39 ;;&#39;你可以在一行中运行多个语句的字符。

EventId eq 4096 and Timestamp gt datetime'2016-06-24T08:20:00' and Timestamp lt datetime'2016-06-24T10:00:00'
相关问题