1

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?

1 Answers1

0

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
  • I asked a similar question on discord: https://discord.com/channels/423249981340778496/423250272316293120/1055260242373525567 It seems the documentation is missing the `window` argument. Your original function had 3 arguments, but there are actually 4 coming from the event, plus `self` makes 5, which you stumbled upon too. – Erik Iverson Jan 11 '23 at 00:21