# Button function running when using an integer

**URL:** <https://discuss.python.org/t/button-function-running-when-using-an-integer/59728>\
**Category:** Python Help\
**Created:** [August 1, 2024, 2:45pm UTC](https://discuss.python.org/t/button-function-running-when-using-an-integer/59728 "2024-08-01T14:45:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OGNinjaDon](https://avatars.discourse-cdn.com/v4/letter/o/c0e974/32.png) [@OGNinjaDon](https://discuss.python.org/u/OGNinjaDon)\
**Post date:** [August 1, 2024, 2:45pm UTC](https://discuss.python.org/t/button-function-running-when-using-an-integer/59728/1 "2024-08-01T14:45:18Z")

</div>

I’m fairly new to Python but understand the basics of programming, I’ve come across an issue I don’t understand and trying to research this online is proving difficult.

scene1Btn.configure(text = ‘Preset Recall 1’, command = recall1)

This line of code appears in the initialise buttons section, if I keep it this way it will run the “recall1” function.

If I amend the code to try and reduce lines of code and have it say:

scene1Btn.configure(text = ‘Preset Recall 1’, command = recall(1))

I can make 1 function and adjust all values in the function based on the integer I send into it, but the problem is, when I make this change, the program runs the function without me pressing the button.

In this program there are 2 of these ‘preset’ buttons, so the program essentially runs the function twice with different values and then doesn’t update no matter which preset button I press.

If I change it back to being 2 seperate functions without the (1) and call it recall1 it doesn’t run the functions and the code works fine.

Very strange and I don’t understand why!

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [August 1, 2024, 4:18pm UTC](https://discuss.python.org/t/button-function-running-when-using-an-integer/59728/2 "2024-08-01T16:18:22Z")

</div>

`recall(1)` calls `recall`, so `scene1Btn.configure(text = ‘Preset Recall 1’, command = recall(1))` is calling `recall` and then passing the result to `configure`.

---

<div class="post-metadata">

**Author:** ![moosemaimer](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/moosemaimer/32/15091_2.png) [@moosemaimer](https://discuss.python.org/u/moosemaimer)\
**Post date:** [August 1, 2024, 5:12pm UTC](https://discuss.python.org/t/button-function-running-when-using-an-integer/59728/3 "2024-08-01T17:12:37Z")

</div>

> <https://stackoverflow.com/questions/6920302/how-to-pass-arguments-to-a-button-command-in-tkinter>

use `functools.partial`

```python
button = tk.Button(window, text = 'text', action = partial(func, *args))

```

---

<div class="post-metadata">

**Author:** ![OGNinjaDon](https://avatars.discourse-cdn.com/v4/letter/o/c0e974/32.png) [@OGNinjaDon](https://discuss.python.org/u/OGNinjaDon)\
**Post date:** [August 5, 2024, 7:23am UTC](https://discuss.python.org/t/button-function-running-when-using-an-integer/59728/4 "2024-08-05T07:23:15Z")

</div>

Thanks everyone for their contribution, I just wanted to share the solution I used which worked and the one I thought was the cleanest.

command = lambda: recall(1))
