我想在猕猴桃中创建DropDown列表吗?我参考了文档,其中在Python文件本身中添加了用于打开Button列表的主DropDown小部件。但是,我想在相关的.kv文件中而不是在python文件中添加主要的Button小部件。
我的代码如下:
main.pyfrom kivy.app import App
from kivy.uix.dropdown import DropDown
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
class drop_content(DropDown):
pass
class Grid_5(GridLayout):
drop = drop_content()
def show_drop(self):
self.drop.open()
class Demo_9(App):
def build(self):
return Builder.load_file("kv\Design8.kv")
if __name__ == "__main__":
Demo_9().run()
Design8.kv:
Label:
text:"Drop1"
size_hint_y: None
height: 44
Label:
text:"Drop2"
size_hint_y: None
height: 44
Grid_5:
cols: 1
Button:
text: "Press me !!"
size_hint: None, None
on_press: root.show_drop()
我得到的错误是:文件“ c:/ Users / pavan m sunder / tutorials / Kivy / py / tut10.py”,第19行,在show_drop中self.drop.open()
TypeError:open()缺少1个必需的位置参数:'widget'