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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.