Python,Kivy,"AssertionError:无人不能调用"通过按钮调用函数时出错 [英] Python, Kivy, "AssertionError: None is not callable" Error on function call by button
本文介绍了Python,Kivy,"AssertionError:无人不能调用"通过按钮调用函数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我希望使用此代码在按下按钮时调用一个函数:
So I whant to use this code to call a function on a button press:
botao_ok.bind(on_press=f_adicionar_socios(txt_n_socio.text,txt_nome.text,txt_filho_de.text,txt_filho_e_de.text,txt_data_nas.text,txt_tipo_ID.text,txt_num_ID.text,txt_NIF.text,txt_morada_rua.text,txt_morada_localidade.text,txt_codigo_postal.text,txt_tel_fixo.text,txt_telemovel.text,txt_email.text,txt_tipo_socio.text,txt_data_admicao.text,txt_zona.text,txt_actividade.text,txt_actividade_de.text,txt_actividade_ate.text,txt_observacoes.text))
但是为了简单起见,我只需要解决这个问题:
But to keep it simple, I only need to solve this problem:
#My Function
def teste_(nome):
print nome
#Button
botao_ok.bind(on_press=teste_('Ola'))
# Button is inside a Class MYApp
并显示错误消息:AssertionError:None不可调用
and it gives the error: AssertionError: None is not callable
我竭尽全力,无法解决这个问题... 谢谢
Ive tryied everything I tough off and can't solve this... Thank you
推荐答案
编写teste_('Ola')
时,该函数运行并返回None
When you write teste_('Ola')
the function runs and returns None
所以当你写
botao_ok.bind(on_press=teste_('Ola'))
它实际上设置为:
botao_ok.bind(on_press=None)
简而言之是造成您的问题的原因.
Which in short is causing your problem.
为了使其能够调用teste_('Ola')
按下按钮时,您可以使用lambda函数:
In order to get it to call teste_('Ola')
When the button is pressed, you could use a lambda function:
botao_ok.bind(on_press=lambda x:teste_('Ola'))
这篇关于Python,Kivy,"AssertionError:无人不能调用"通过按钮调用函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文