Kivy:拖放,获取文件路径 [英] Kivy: drag n drop, get file path

查看:18
本文介绍了Kivy:拖放,获取文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Kivy 中,我正在尝试构建一个界面,用户可以在其中将文件拖放到小部件(文本输入)中,然后我的代码将检索该文件的文件系统路径(/path/to/users.文件).这似乎比使用 FileChooser 小部件更简单,但我该怎么做呢?

In Kivy, I am trying to build an interface where the user can drag and drop a file into a widget (text input) and then my code would retrieve the file system path of that file (/path/to/users.file). That seems like a simpler approach than using the FileChooser widget, but how would I do it?

谢谢!

推荐答案

使用on_dropfile 事件处理程序.这是一个工作示例:

Use on_dropfile event handler. Here is an working example:

from kivy.app import App
from kivy.core.window import Window


class WindowFileDropExampleApp(App):
    def build(self):
        Window.bind(on_dropfile=self._on_file_drop)
        return

    def _on_file_drop(self, window, file_path):
        print(file_path)
        return

if __name__ == '__main__':
    WindowFileDropExampleApp().run()

这篇关于Kivy:拖放,获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆