Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python kivymd中的方法在构建器中添加TwoLineIconListItem?_Python_Python 3.x_Kivy_Kivy Language_Kivymd - Fatal编程技术网

如何使用python kivymd中的方法在构建器中添加TwoLineIconListItem?

如何使用python kivymd中的方法在构建器中添加TwoLineIconListItem?,python,python-3.x,kivy,kivy-language,kivymd,Python,Python 3.x,Kivy,Kivy Language,Kivymd,我想用python中的kivy、kivymd制作一个android应用程序。在里面 该应用程序我想添加一个音乐播放器,将自动找到 所有的音乐文件,然后它将添加所有的文件作为 OneLineIconListItem,当我们单击它时,将播放音乐 根据OneLineIconListItem文本的标题,我的意思是 作为一个普通的离线android音乐播放器,它会显示所有的文件(音乐名称)以及我们 点击它将播放歌曲我的代码是-: from kivy.lang import Builder impor


我想用python中的kivy、kivymd制作一个android应用程序。在里面
该应用程序我想添加一个音乐播放器,将自动找到
所有的音乐文件,然后它将添加所有的文件作为
OneLineIconListItem,当我们单击它时,将播放音乐
根据OneLineIconListItem文本的标题,我的意思是
作为一个普通的离线android音乐播放器,它会显示所有的文件(音乐名称)以及我们
点击它将播放歌曲我的代码是-:

   from kivy.lang import Builder
import os
from kivymd.app import MDApp

helper_string = """
Screen:
    name: "Music_Player"
    BoxLayout:
        orientation: "vertical"
        MDToolbar:
        title: "Toolbar"
        elevation: 10

        MDLabel:
        text: "Music_Player" 
"""


class MusicApp(MDApp):
    def build(self):
        screen = Builder.load_string(helper_string)
        return screen

    def getting_all_music_files(self):
        for root, dirs, files in os.walk('C:/'):
            for file in files:
                if file.endswith('.mp3'):
                    required_file = file
                    the_location = os.path.abspath(required_file)

如果要获取文件位置,只需打印_位置并设置目录(在我的示例中为C):/
现在,我想添加一个包含所有位置的for循环,然后将其添加为屏幕中的列表: 盒子布局:
但我不知道如何使用for循环将位置OneLineIconListItem添加到我的应用程序中,当我们单击它时,它将播放歌曲。。

我是编程新手,所以请帮我解决问题

非常感谢,它确实帮了我很多,现在我可以继续前进了
from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem

KV = '''
ScrollView:

    MDList:
        id: container
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        for i in range(20):
            self.root.ids.container.add_widget(
                OneLineListItem(text=f"Single-line item {i}")
            )

Test().run()