Kivy popup Filechooser传递变量(选择)

时间:2018-01-22 16:27:01

标签: python popup kivy filechooser

我想将选择变量从load_file_popup filechooser传递给GUI。当我在选择文件后按下加载按钮时会出现错误

  

TypeError:' NoneType'对象不可调用

这是我的代码(简化)

class GUI(BoxLayout):

    file_path = StringProperty("Currently No File")


    def __init__(self, **kwargs):
        super(GUI, self).__init__(**kwargs)
        self.load_file_popup = load_file_popup()



    def load(self, selection):
        self.file_path = str(selection[0])
        self.dismiss()


class load_file_popup(Popup):

    load = ObjectProperty()

这是kv

<load_file_popup>:
    title: "Select File"
    size_hint: .9, .9
    SMSBoxLayout:
        orientation: "vertical"
        FileChooser:
            id: filechooser   
            FileChooserIconLayout


        SMSBoxLayout:
            size_hint: (1, 0.1)
            pos_hint: {'center_x': .5, 'center_y': .5}
            SMSButton:
                text: "Cancel"
                on_release: root.dismiss()
            SMSButton:
                text: "Load"
                on_release: root.load(filechooser.selection)
                id: ldbtn
                disabled: True if filechooser.selection==[] else False

1 个答案:

答案 0 :(得分:2)

我已经找到了问题的答案,我错过了一个论点。

def __init__(self, **kwargs):
    super(GUI, self).__init__(**kwargs)
    self.load_file_popup = load_file_popup(load=self.load)

def load(self, selection):
    self.file_path = str(selection[0])
    self.load_file_popup.dismiss()
相关问题