【发布时间】:2020-08-03 13:54:48
【问题描述】:
这是我的代码:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty
from kivy.clock import Clock
class MyWidget(Widget):
score = NumericProperty(0)
class MyWindow(Widget):
def update(self, dt):
if self.ids.mywidget.score < 10:
self.ids.mywidget.score += 1
class MyApp(App):
def build(self):
myapp = MyWindow()
Clock.schedule_interval(myapp.update, .25)
return myapp
MyApp().run()
kv:
<MyWindow>:
MyWidget:
id: mywidget
Label:
id: myLabel
text: '0'
font_size: 70
center_x: root.width / 2
center_y: root.height / 2
我必须在我的 python 文件中进行哪些更改才能使应用程序的行为与我的 kv 文件实际上是这样的相同:
<MyWindow>:
MyWidget:
id: mywidget
Label:
id: myLabel
text: str(root.ids.mywidget.score)
font_size: 70
center_x: root.width / 2
center_y: root.height / 2
(我希望标签文本在分数属性更改时更改。)
提前致谢
【问题讨论】:
标签: python user-interface kivy kivy-language