내 목표는 Popup
의 개수를 보는 것입니다. NumericProperty
이로드되었습니다. 그러나 콜백이 호출 될 때 숫자는 변경되지 않습니다. (label.text에 콜백으로 연결되는 코드가 없습니다)Kivy 업데이트 동적 라벨 텍스트
비슷한 질문이 제기되었습니다. 그러나, 나는 그들이이 특별한 경우에 어떻게 적용되는지 볼 수 없었다. 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()
두 답변 모두 완벽하게 작동합니다. – xxLITxx