繁体   English   中英

Kivy中的on_drop_file function for python传5个arguments,但我的drop function中只允许3个arguments

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM