【发布时间】:2019-12-29 07:41:14
【问题描述】:
我在 .kv 中创建下拉列表时遇到问题,所以请任何人帮助我,并提供仅包含 1-10 个数字的下拉列表的代码
【问题讨论】:
-
如果可能,请提供完整的 .py 和 .kv 文件
标签: python python-3.x kivy kivy-language
我在 .kv 中创建下拉列表时遇到问题,所以请任何人帮助我,并提供仅包含 1-10 个数字的下拉列表的代码
【问题讨论】:
标签: python python-3.x kivy kivy-language
您可以使用official documentation作为参考
.kv
<CustomDropDown>:
Button:
text: 'My first Item'
size_hint_y: None
height: 44
on_release: root.select('item1')
Label:
text: 'Unselectable item'
size_hint_y: None
height: 44
Button:
text: 'My second Item'
size_hint_y: None
height: 44
on_release: root.select('item2')
.py
class CustomDropDown(DropDown):
pass
dropdown = CustomDropDown()
mainbutton = Button(text='Hello', size_hint=(None, None))
mainbutton.bind(on_release=dropdown.open)
dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
【讨论】: