下拉菜单 KivyMD 剂量显示
Posted
技术标签:
【中文标题】下拉菜单 KivyMD 剂量显示【英文标题】:dropdown menu KivyMD dosent shows 【发布时间】:2021-11-27 07:06:52 【问题描述】:我是 kivy/kivymd 的新手,我正在尝试通过 kivymd 文档创建一个下拉菜单。但是,每当我单击下拉菜单时,它都会向我返回此错误: app.dropdown.open(self) TypeError: open() 接受 1 个位置参数,但给出了 2 个
from kivy.properties import ObjectProperty
from kivymd.uix.menu import MDDropdownMenu
from kivymd.app import MDApp
import win32api
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
class YouTubeDownloader(MDApp):
dropdown = ObjectProperty()
def on_start(self):
self.dropdown = MDDropdownMenu()
for i in drives:
self.dropdown.items.append(
"viewclass":"MDMenuItem",
"text":str(i),
"callback": self.menu_callback
) def menu_callback(self, text_item):
print(text_item)
YouTubeDownloader().run()
KV 文件
BoxLayout:
orientation:"vertical"
MDToolbar:
title:"YouTube Downloader"
md_bg_color: app.theme_cls.primary_color
BoxLayout:
orientation:"vertical"
MDTextField:
hint_text: "Enter the URL here"
size_hint: 0.4,0.15
pos_hint:"center_x":0.5,"center_y":0.5
MDRaisedButton:
id: dropdown
text: "Select Path"
pos_hint:"center_x":0.5
on_release:
app.dropdown.open(self)
GridLayout:
cols:3
AsyncImage:
id: image
source: "https://i.ytimg.com/vi/LRXo0juuTrw/maxresdefault.jpg"
AsyncImage:
source: "https://i.ytimg.com/vi/LRXo0juuTrw/maxresdefault.jpg"
AsyncImage:
source: "https://i.ytimg.com/vi/LRXo0juuTrw/maxresdefault.jpg"
AsyncImage:
source: "https://i.ytimg.com/vi/LRXo0juuTrw/maxresdefault.jpg"
MDRaisedButton:
text:"Download"
pos_hint:"center_x":0.5
在运行此代码时,我收到一条错误消息
app.dropdown.open(self)
TypeError: open() takes 1 positional argument but 2 were given
有人可以帮忙吗?
【问题讨论】:
【参考方案1】:改变
app.dropdown.open(self)
作者:
app.dropdown.open()
【讨论】:
以上是关于下拉菜单 KivyMD 剂量显示的主要内容,如果未能解决你的问题,请参考以下文章