简体   繁体   English

kivy NumericProperty问题

[英]kivy NumericProperty issue

I am working on incrementer app, and this is my code. 我正在使用增量器应用程序,这是我的代码。

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.properties import NumericProperty

value = NumericProperty(0)

class documentScreen(GridLayout):
    def __init__(self, **kwargs):
        super(documentScreen, self).__init__(**kwargs)

        self.cols = 1
        self.inc = Button(text='++')
        self.add_widget(self.inc)
        self.add_widget(Label(text=str(value)))

class MainScreen(App):
    def build(self):
        return documentScreen()

if __name__=='__main__':
    MainScreen().run()

but when i an run the code, Label display as <NumericProperty name=> instead of 0. It's doesn't display 0. 但是当我运行代码时,Label显示为<NumericProperty name=>而不是0。它不会显示0。

Kivy properties are defined at class level. Kivy属性是在类级别定义的。 So you need to put your NumericProperty one line above the init method of your DocumentScreen class. 因此,您需要将NumericProperty放在DocumentScreen类的init方法上方一行。 You made it a global variable which doesn't make sense. 您将其设置为没有任何意义的全局变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM