【发布时间】:2017-10-08 04:52:17
【问题描述】:
我的目标是查看Popup 上的数字。我有一个 NumericProperty 正在加载。但是,调用回调时数字不会改变。 (我在回调中没有任何代码链接到 label.text)
已提出类似问题。但是,我一直无法看到它们如何适用于这个特定案例。 Similar Case
import kivy
kivy.require("1.7.0")
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.properties import NumericProperty
from kivy.clock import Clock
from kivy.event import EventDispatcher
scoreInc = 0
class MyPopup(Popup):
def show_popup(self):
content = BoxLayout(orientation="vertical")
self.incrementerFnc = Clock.schedule_interval(self.incrementer, .005)
scoreLabel = Label(text=str(ins.a), id='scorelabel', font_size=20)
content.add_widget(scoreLabel)
mybutton = Button(text="Close", size_hint=(1,.20), font_size=20)
content.add_widget(mybutton)
mypopup = Popup(content = content,
title = "Score",
auto_dismiss = False,
size_hint = (.7, .5),
font_size = 20)
mybutton.bind(on_press=mypopup.dismiss)
mypopup.open()
def incrementer(self, dt):
global scoreInc
scoreInc += 1
ins.a = scoreInc
if(scoreInc >= 10):
Clock.unschedule(self.incrementerFnc)
print('quit')
else:
print('scoreInc', ins.a)
class MyClass(EventDispatcher):
a = NumericProperty(0)
def callback(instance, value):
print('My callback is call from', instance)
print('and the a value changed to', value)
ins = MyClass()
ins.bind(a=callback)
class MyApp(App):
def build(self):
mypopup = MyPopup()
return mypopup.show_popup()
if __name__ == "__main__":
MyApp().run()
【问题讨论】:
标签: properties label kivy