8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Python Kivy】ドラッグ&ドロップでファイルパス取得方法

Last updated at Posted at 2017-04-28

#ファイルをドラッグしてパスを取得する方法

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

    #自分で定義するイベント処理メソッド
    def _on_file_drop(self, window, file_path):
        print(file_path)
            return

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

これを利用して、ウィンドウを作成verを以下のように作った。ウィンドウ自体に、ファイルパス取得の機能をつけることになるのかなぁ、、、初心者感丸出し笑

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

    #ドロップオブジェクト?をプロパティとして保存
        self._file = Window.bind(on_dropfile=self._on_file_drop)

    #自分で定義する処理メソッド
    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()

目標はドロップして、CSVファイルを読み込んでRにデータを流すこと、、、

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?