[英]Kivy: drag n drop, get file path
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). 在Kivy中,我正在尝试构建一个界面,用户可以将文件拖放到窗口小部件(文本输入)中,然后我的代码将检索该文件的文件系统路径(/path/to/users.file)。 That seems like a simpler approach than using the FileChooser widget, but how would I do it? 这似乎比使用FileChooser小部件更简单,但我该怎么做呢?
Thanks! 谢谢!
Use on_dropfile
event handler. 使用on_dropfile
事件处理程序。 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.