我很难理解如何保存用户输入。我已经研究了在网上找到的其他草图,但是正在为这个概念而苦苦挣扎。以下是说明我的问题的草图。与保存文本输入有关的所有代码均在下面进行了细分。
我遇到了错误:
AttributeError: 'CustomPopup1' object has no attribute 'save'
也就是说,如何在弹出窗口中保存文本输入?
这是我的代码:
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemandmulti')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.storage.jsonstore import JsonStore
theRoot = Builder.load_string('''
<CustomPopup1>:
size_hint: .9, .9
auto_dismiss: False
title: "Program 1"
StackLayout:
Label:
text: "Select Start Hour"
size_hint: .2, .2
TextInput:
size_hint: .2, .2
id: p1sh1
Label:
text: "Select Start Minute"
size_hint: .2, .2
TextInput:
size_hint: .2, .2
id: p1sm1
Button:
text: "Close"
on_press: root.dismiss()
size_hint: .5, .25
#--------------------------here-----------------------------------------
Button:
text: 'save'
on_release: on_release: root.save(CustomPopup1)
size_hint: .5, .25
#----------------------------------------------------------------------
StackLayout:
orientation: 'lr-tb'
padding: 10
spacing: 5
Button:
text: "Open Popup"
on_press: app.open_popup1()
size_hint: .5,.1
''')
class CustomPopup1(Popup):
pass
class theApp(App):
def build(self):
return theRoot
def open_popup1(self):
the_popup = CustomPopup1()
the_popup.open()
#-----------------------here--------------------------------------------
def save(self, vinput):
store = JsonStore('hello.json')
store.put('tito', inpud=vinput)
#-----------------------------------------------------------------------
if __name__ == '__main__':
theApp().run()
谢谢您的帮助,感谢您的反馈:)