KivyMD 问题 / KivyMD 问题
Pr0blem with KivyMD / Проблема с KivyMD
如何将 id 变量从 kv 文件传递到其余代码?他没有看到她。例如这段代码:如何确保没有错误并打印出所有内容?我已经在俄语和西班牙语 Whosebug 中问过这个问题,但没有人回答我
KV = '''
Screen:
MDRaisedButton:
text: 'button'
pos_hint: {'center_x':.5,'center_y':.4}
on_press: app.func()
MDTextField:
id: text
pos_hint: {'center_x':.5,'center_y':.5}
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def func():
print(text.text)
Test().run()
只需将您的 func()
更改为:
def func(self):
print(self.root.ids.text.text)
如何将 id 变量从 kv 文件传递到其余代码?他没有看到她。例如这段代码:如何确保没有错误并打印出所有内容?我已经在俄语和西班牙语 Whosebug 中问过这个问题,但没有人回答我
KV = '''
Screen:
MDRaisedButton:
text: 'button'
pos_hint: {'center_x':.5,'center_y':.4}
on_press: app.func()
MDTextField:
id: text
pos_hint: {'center_x':.5,'center_y':.5}
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def func():
print(text.text)
Test().run()
只需将您的 func()
更改为:
def func(self):
print(self.root.ids.text.text)