本文介紹了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:拖放,獲取文件路徑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!