【问题标题】:Kivy popup Filechooser pass variable (selection)Kivy 弹出 Filechooser 传递变量(选择)
【发布时间】:2018-07-01 08:27:25
【问题描述】:

我想将选择变量从 load_file_popup 文件选择器传递到 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()

这里是千伏

<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

【问题讨论】:

    标签: python popup kivy filechooser


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多