問(wèn)題描述
所以我想使用此代碼在按下按鈕時(shí)調(diào)用函數(shù):
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))
但為了簡(jiǎn)單起見(jiàn),我只需要解決這個(gè)問(wèn)題:
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
它給出了錯(cuò)誤:AssertionError: None is not callable
and it gives the error: AssertionError: None is not callable
我已經(jīng)嘗試了所有我強(qiáng)硬的方法但無(wú)法解決這個(gè)問(wèn)題......謝謝
Ive tryied everything I tough off and can't solve this... Thank you
推薦答案
當(dāng)你編寫(xiě) teste_('Ola')
函數(shù)運(yùn)行并返回 None
When you write teste_('Ola')
the function runs and returns None
所以當(dāng)你寫(xiě)的時(shí)候
botao_ok.bind(on_press=teste_('Ola'))
它實(shí)際上被設(shè)置為:
botao_ok.bind(on_press=None)
簡(jiǎn)而言之,這是導(dǎo)致您的問(wèn)題的原因.
Which in short is causing your problem.
為了讓它調(diào)用 teste_('Ola')
當(dāng)按鈕被按下時(shí),你可以使用 lambda 函數(shù):
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'))
這篇關(guān)于Python,Kivy,“AssertionError: None is not callable"按鈕調(diào)用函數(shù)時(shí)出錯(cuò)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!