[英]Wrapper function that reads arguments from file and then passes to subroutines in python3
[英]The on_drop_file function in Kivy for python passes 5 arguments, but only 3 arguments are allowed in my drop function
我正在關注這個 - Kivy:拖放,從 stackoverflow 獲取文件路徑教程,以便在我的 kivy gui 應用程序中實現拖放文件功能。 但是,當我運行示例代碼時:
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()
我收到一條消息說 on_dropfile 功能已被棄用,我應該改用 on_drop_file 功能。 在將其更改為 on_drop_file 后,在以下代碼中:
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.uix.button import Label
from kivy.core.window import Window
class Gui(App):
def build(self):
Window.bind(on_drop_file=self._on_file_drop)
return Label(text = "Drag and Drop File here")
def _on_file_drop(self, window, file_path):
print(file_path)
return
if __name__ == '__main__':
drop = Gui()
drop.run()
我收到以下錯誤:
TypeError: Gui._on_file_drop() takes 3 positional arguments but 5 were given
我似乎找不到我應該包含的 5 位置 arguments 是什么。 應該如何修改我的_on_file_drop()
function 以使其工作?
這個問題可以通過在on_file_drop()
function 中創建任意 x 和 y arguments 來解決,如下所示:
def _on_file_drop(self, window, file_path, x, y):
print(file_path)
return
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.