本文介紹了Kivy:拖放,獲取文件路徑的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問題描述
在 Kivy 中,我正在嘗試構(gòu)建一個(gè)界面,用戶可以在其中將文件拖放到小部件(文本輸入)中,然后我的代碼將檢索該文件的文件系統(tǒng)路徑(/path/to/users.文件).這似乎比使用 FileChooser 小部件更簡(jiǎn)單,但我該怎么做呢?
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
事件處理程序.這是一個(gè)工作示例:
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()
這篇關(guān)于Kivy:拖放,獲取文件路徑的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!