kivy python passing parameters to fuction with button click
<p>I am having trouble passing parameters to function when calling it with button press. One could do it like this in kivy language:</p>

<pre><code>Button: 
   on_press: root.my_function('btn1')
</code></pre>

<p>but I would like to do it in python, as I would like to create a larger number of buttons with a loop. Currently I call my function in python like this:</p>

<pre><code>Button(on_press=self.my_function)
</code></pre>

<p>but as I said, if I try to pass a parameter to the function like this, I get an 'AssertionError: None is not callable', like this:</p>

<pre><code>Button(on_press=self.my_function('btn1'))
</code></pre>

<pre><code>Button(on_press=self.my_function)
</code></pre>

<p>This is <em>passing</em> the function as an argument.</p>

<pre><code>Button(on_press=self.my_function('btn1'))
</code></pre>

<p>This is <em>calling</em> the function and passing the <em>returned value</em> as the argument to <code>on_press</code>. Since the returned value is None, you get your error.</p>

<p>You instead need to pass a new function that calls your normal function and automatically passes the argument. In general, it's convenient to use <code>functools.partial</code>:</p>

<pre><code>from functools import partial
Button(on_press=partial(self.my_function, 'btn1'))
</code></pre>

<p>You can also use a lambda function:</p>

<pre><code>Button(on_press=lambda *args: self.my_function('btn1', *args))
</code></pre>

python function button kivy