0
仍然在這裏學習Python和Kivy,並繼續從this問題,並且將數據結構(字典)解析爲屏幕有點困惑。Kivy - 解析對屏幕結構的引用
什麼是解析所述數據結構到屏幕的最佳方式是什麼?
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import NumericProperty
class TestWidget(RelativeLayout):
def __init__(self, testStructTable, **kwargs):
super(TestWidget, self).__init__(**kwargs)
Builder.load_file('test.kv')
self.testStructTable = testStructTable
sm = ScreenManager()
# This line here to parse the data structure?
sm.add_widget(MainScreen(name='MainScreen'), testStructTable)
self.add_widget(sm)
Clock.schedule_interval(MainScreen.update_test_val(testStructTable), 1/60)
class MainScreen(Screen):
testVal = NumericProperty(0)
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
# would like to parse the testStructTable here?
# self.testStructTable = testStructTable
def update_test_val(dt, self):
self.testVal = testStructTable['testVal']