2

on_dropfile複数のオブジェクトをバインドすることは可能ですか? それとも、常に 1 つのバインドのみですか?

私はクラスをデカールしました

class dropFile(Label):
    def __init__(self, **kwargs):
        super(dropFile, self).__init__(**kwargs)
        Window.bind(mouse_pos=lambda w, p: setattr(helper, 'mpos', p))
        Window.bind(on_dropfile=self.on_dropfile)

    def on_dropfile(self, *args):
        print ("ding")
        if (self.center_x - self.width/2 < helper.mpos[0] < self.center_x + self.width/2 and
                self.center_x - self.height/2 < helper.mpos[1] < self.center_y + self.height/2):
            print('dong')
            self.text = str(args[1])

そしてkvでは、私はそれを次のように使用します

dropFile:
    text: "Please drop file1"
dropFile:
    text: "Please drop file2"

ただし、最初のフィールドでのみ機能します (「ファイル 1 をドロップしてください」フィールドにドロップされたファイルのみが表示されます。それ以外の場合は、ドロップを受け取りますが、それが 2 番目のフィールドの境界内にあることを認識できません。on_dropfile最初のオブジェクトの関数をバインドします)。

複数のオブジェクトに実装するエレガントな方法はありますか?

4

1 に答える 1