3 가지 클래스가 있다고 가정 해 봅시다. 물건이 들어있는 "워킹 클래스", 라벨 클래스 및 라벨을 포함하는 클래스입니다. 예를 들어 레이블 클래스는 작업 클래스에서 진행되는 작업의 상태를 나타내는 상태 표시 줄 일 수 있습니다. 이 값은 후자의 내부에서 변경되는 작업 클래스의 값이기 때문에 레이블에 표시 할 값을 자체 업데이트 할 수있는 방법을 찾을 수 있기를 바랍니다. 여기Kivy : 자체 업데이트 라벨 텍스트
나는 속성 또는 무엇 이건 그것을하는 방법이 있나요 예제 코드
Builder.load_string('''
<CustomLabel>
text: 'Value is {}'.format(root.value)
<WorkingClass>:
orientation: 'vertical'
Button:
text: 'Update'
on_release: root.update()
<MainLayout>
orientation: 'vertical'
''')
class CustomLabel(Label):
value = NumericProperty()
class WorkingClass(BoxLayout):
def __init__(self, *args, **kwargs):
super(WorkingClass, self).__init__(*args, **kwargs)
self.a = 5
def update(self):
self.a += 1
print(self.a)
class MainLayout(BoxLayout):
def __init__(self, *args, **kwargs):
super(MainLayout, self).__init__(*args, **kwargs)
self.workingClass = WorkingClass()
self.customLabel = CustomLabel(value=self.workingClass.a)
self.add_widget(self.customLabel)
self.add_widget(self.workingClass)
class MyApp(App):
def build(self):
return MainLayout()
if __name__ == "__main__":
MyApp().run()
있나요? Becouse 나는 값을 변경할 때마다 레이블을 수동으로 업데이트 (sommehow)하고 싶지 않습니다. 어쨌든 이것을 달성하기 위해서?
대단히 감사합니다. 나는 세터에 대해 몰랐어! 난 항상 네가 내 kivy 질문에 대답하는 것을 알아 차렸다. – UfoRobot