1 回答
TA贡献1833条经验 获得超4个赞
实际上,我建议您将 ScreenManager 与 kivy 一起使用。这样您就可以轻松地使用 Properties。
但是对于此解决方案,您可以使用:
from kivy.app import App
from kivy.lang import Builder
kv_string = """
#:import choice random.choice
BoxLayout:
orientation: 'vertical'
Label:
id: mylabel
text: "Truth or Dare?"
TextInput:
id: myinput
hint_text: "Two Things To Try: Truth or Dare"
Button:
text: "Generate"
on_release: root.ids.mylabel.text = choice(app.my_list)
"""
class MyApp(App):
def build(self):
with open('asd.txt', 'r') as mytxt:
self.my_list = mytxt.readlines()
return Builder.load_string(kv_string)
if __name__ == '__main__':
MyApp().run()
添加回答
举报