Kivy:拖动n放下,获取文件路径 [英] Kivy: drag n drop, get file path
本文介绍了Kivy:拖动n放下,获取文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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?
谢谢!
推荐答案
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:拖动n放下,获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文