我有一个带有Popup的代码,其中包含TextInput。示例中的表单代码是有效的,但是使用TextInputPopup构造函数在使用后会下降弹出窗口。打开()(注释中有构造器的版本)。在
示例:
Builder.load_string('''
<SaveAs>:
teinp: teinp
Button:
text:'Hi users'
on_release: root.on_call_popup()
TextInput:
id: teinp
text:'text input'
<TextInputPopup>:
answer: answer
title: root.title
size_hint: None, None
size: app.root.width/2, app.root.height/2
auto_dismis: False
BoxLayout:
orientation: 'vertical'
Label:
text: root.label
TextInput:
id: answer
text: ''
BoxLayout:
Button:
text: 'Cancel'
on_press: root.dismiss()
Button:
text: 'OK'
on_press: root.dismiss()
''')
class TextInputPopup(Popup):
title = StringProperty()
label = StringProperty()
answer = ObjectProperty()
'''
def __init__ (self,title, label):
self.set_description(title, label)
return
'''
def set_description(self,title, label):
self.title = title
self.label = label
return
def get_answer(self):
return self.answer.text
class SaveAs(BoxLayout):
teinp = ObjectProperty()
def on_call_popup(self):
self.poti = TextInputPopup()
# self.poti = TextInputPopup('File Manager', 'Name')
self.poti.open()
self.poti.set_description('File Manager', 'Name')
self.poti.bind(on_dismiss = self.next_step)
return
def next_step(self, obj):
a = self.poti.get_answer()
self.teinp.text = self.poti.get_answer()
return
class ExplorerApp(App):
def build(self):
return SaveAs()
if __name__ == '__main__':
ExplorerApp().run()
必须调用父类的初始值设定项(} :
__init__
),才能使用^{如果在派生的类中使用},并允许您向父类传递参数。在
__init__
,则是在重新定义父构造函数,该构造函数通常会运行基类的初始化。super
用于在不显式调用父类的情况下运行父类{原则上,每当您重写子类中的
__init__
时,您应该调用父类的__init__
,并使用必要的参数正确初始化。在相关问题 更多 >
编程相关推荐