【问题标题】:Filemanager code using kivymd is not functioning使用 kivymd 的文件管理器代码不起作用
【发布时间】:2020-04-19 16:14:34
【问题描述】:

我想使用 kivymd 创建一个文件管理器,所以我找到了下面的代码,但是每当我运行它并按下“打开管理器”按钮时 - 应该在发布时打开文件管理器 - 什么都没有发生。

from kivy.core.window import Window
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.filemanager import MDFileManager
from kivymd.toast import toast

这是GUI设计的一部分

KV = '''
BoxLayout:
    orientation: 'vertical'

    MDToolbar:
        title: "MDFileManager"
        left_action_items: [['menu', lambda x: None]]
        elevation: 10

    FloatLayout:

        MDRoundFlatIconButton:
            text: "Open manager"
            icon: "folder"
            pos_hint: {'center_x': .5, 'center_y': .6}
            on_release: app.file_manager_open()
'''

这里是打开文件管理器的功能

class Example(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        Window.bind(on_keyboard=self.events)
        self.manager_open = False
        self.file_manager = MDFileManager(
            exit_manager=self.exit_manager,
            select_path=self.select_path,
            previous=True,
        )

    def build(self):
        return Builder.load_string(KV)

    def file_manager_open(self):
        self.file_manager.show('/')  # output manager to the screen
        self.manager_open = True

    def select_path(self, path):
        '''It will be called when you click on the file name
        or the catalog selection button.

        :type path: str;
        :param path: path to the selected directory or file;
        '''

        self.exit_manager()
        toast(path)

    def exit_manager(self, *args):
        '''Called when the user reaches the root of the directory tree.'''

        self.manager_open = False
        self.file_manager.close()

    def events(self, instance, keyboard, keycode, text, modifiers):
        '''Called when buttons are pressed on the mobile device.'''

        if keyboard in (1001, 27):
            if self.manager_open:
                self.file_manager.back()
        return True


Example().run()

【问题讨论】:

    标签: python-3.x kivy-language file-manager


    【解决方案1】:

    这可能有点晚了,但该示例不适用于最新版本 (0.104.1)。它仅适用于 0.104.2(开发版)。

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 2021-04-11
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 2018-12-29
      相关资源
      最近更新 更多