[Python Kivy] How to get the file path by dragging and dropping

How to get the path by dragging the file

FileDrop.py


from kivy.app import 
from kivy.core.window import Window

class FileDropApp(App):
    def build(self):
        Window.bind(on_dropfile == self._on_file_drop)
        return

    #Event handling method you define
    def _on_file_drop(self, window, file_path):
        print(file_path)
            return

if __name__ == '__main__':
    FileDropApp().run()

Using this, I made a window creation ver as follows. I wonder if the window itself will have a file path acquisition function ...

MyApp.py


from kivy.app import App
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle

class Field(Widget):
    def __init__(self):
        super(Field, self).__init__()
        self.canvas.add(Rectangle(
            source="background.jpg ", size = (1024,768)))

    #Drop object? As a property
        self._file = Window.bind(on_dropfile=self._on_file_drop)

    #Processing method defined by yourself
    def _on_file_drop(self, window, file_path):
        print(file_path)
        return

class MyApp(App):
    def build(self):
        return Field()

if __name__ == '__main__':
    MyApp().run()

The goal is to drop, read the CSV file and stream the data to R ...

Recommended Posts

[Python Kivy] How to get the file path by dragging and dropping
How to get the Python version
How to switch the configuration file to be read by Python
Get the path to the systemd unit file
How to get and set the NTP server name by DHCP
How to get followers and followers from python using the Mastodon API
[Python] How to get the first and last days of the month
How to get the date and time difference in seconds with python
How to erase the characters output by Python
How to get the files in the [Python] folder
How to get started with the 2020 Python project (windows wsl and mac standardization)
I want to get the file name, line number, and function name in Python 3.4
How to get the variable name itself in python
How to get the number of digits in Python
[Python] Get the official file path of the shortcut file (.lnk)
Read the xml file by referring to the Python tutorial
How to execute a schedule by specifying the Python time zone and execution frequency
Get the MIME type in Python and determine the file format
How to get the last (last) value in a list in Python
How to get all the keys and values in the dictionary
How to get into the python development environment with Vagrant
[Python Kivy] How to create an exe file with pyinstaller
[Introduction to Python] How to get data with the listdir function
Get the desktop path in Python
Python> library> os> os.walk ()> Get directory structure / Implementation to get each file path in the specified directory
Get the script path in Python
How to get started with Python
[Python] How to import the library
Get the desktop path in Python
Get the file path using Pathlib
How to pass and study the Python 3 Engineer Certification Basic Exam
python / pandas / dataframe / How to get the simplest row / column / index / column
Try to implement and understand the segment tree step by step (python)
[Beginner memo] How to specify the library reading path in Python
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
How to display bytes in the same way in Java and Python
How to get the pixel value of the point from the satellite image by specifying the latitude and longitude
[Python] How to convert db file to csv
How to package and distribute Python scripts
How to install and use pandas_datareader [Python]
[Kivy] How to install Kivy on Windows [Python]
How to convert Python to an exe file
How to get a stacktrace in python
Read the file line by line in Python
Read the file line by line in Python
How to get colored output to the console
python: How to use locals () and globals ()
[Python] How to calculate MAE and RMSE
How to use Python zip and enumerate
[Python] Get the character code of the file
How to use is and == in Python
[Python] How to specify the window display position and size of matplotlib
How to write the correct shebang in Perl, Python and Ruby scripts
Learning record (4th day) #How to get the absolute path from the relative path
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
[Python] How to use the enumerate function (extract the index number and element)
The file name was bad in Python and I was addicted to import
I tried to verify and analyze the acceleration of Python by Cython
How to automatically notify by phone when the python system is down
How to sort by specifying a column in the Python Numpy array.
How to use the C library in Python