【发布时间】:2015-06-15 14:34:50
【问题描述】:
我想使用 DropDown 类获得一个简单的组合框,例如小部件。我可以使用 python 代码来完成,但是否可以只使用 kv 语言?
我尝试了以下方法。这是我的python代码:
class CustomDropDown(DropDown):
pass
class MainForm(BoxLayout):
pass
class MainApp(App):
def build(self):
self.dropdown = CustomDropDown()
self.mainForm = MainForm()
return self.mainForm
def do_something(self):
self.dropdown.open(self.mainForm)
MainApp().run()
这是 kv 文件:
<MainForm>:
Button:
text: 'Press'
size_hint: [None,None]
height: '40dp'
on_release: app.do_something()
<CustomDropDown>:
Button:
text: 'First Item'
Label:
text: 'Disabled item'
Button:
text: 'Second Item'
但这不起作用。你能建议点什么吗?任何帮助表示赞赏。
【问题讨论】: