![](/img/trans.png)
[英]How do I add a Kivy drop-down menu made in the .py file from the .kv file?
[英]How to create the drop-down list in kivy with .kv file
我在 .kv 中創建下拉列表時遇到問題,所以任何人都可以幫助我並給我僅包含 1-10 個數字的下拉列表的代碼
您可以使用官方文檔作為參考
.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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.