'The on_drop_file function in Kivy for python passes 5 arguments, but only 3 arguments are allowed in my drop function

I was following this - Kivy: drag n drop, get file path tutorial from stackoverflow in order to implement a drag and drop file feature in my kivy gui application. However, when I ran the example code :

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()

I got a message saying that the on_dropfile feature was deprecated and that I should use the on_drop_file feature instead. Upon changing it to on_drop_file, in the following code:

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()

I got the following error:

 TypeError: Gui._on_file_drop() takes 3 positional arguments but 5 were given

I can't seem to find what the 5 positional arguments that I'm supposed to include are. How should my _on_file_drop() function be modified to make this work?



Solution 1:[1]

This issue can be resolved by just creating arbitrary x and y arguments in the on_file_drop() function, which would look like the following:

 def _on_file_drop(self, window, file_path, x, y):
        print(file_path)
        return

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aaroh Gokhale