Kivy弹出Filechooser传递变量(选择) [英] Kivy popup Filechooser pass variable (selection)
本文介绍了Kivy弹出Filechooser传递变量(选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将选择变量从load_file_popup filechooser传递给GUI.当我选择文件后按加载"按钮时,显示错误
i want to pass selection variable from load_file_popup filechooser to GUI. when i press load button after selecting a file it gives error
TypeError:"NoneType"对象不可调用
TypeError: 'NoneType' object is not callable
这是我的代码(简体)
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
推荐答案
我想出了我的问题的答案,我错过了一个论点.
I have figured out answer of my problem, i was missing an argument.
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()
这篇关于Kivy弹出Filechooser传递变量(选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文