0
from tkinter import * 

def my_function(parameter1, parameter2):
    total = int(entrada1.get()) + int(entrada2.get())
    Label(root,text=calculated_property).pack()

root = Tk()
frame = Frame(root)  
frame.pack()  

root.title("Testing 123")

numero1 = IntVar()
numero2 = IntVar()
entrada1 = Entry(root,textvariable=numero1)
entrada1.pack()
entrada2 = Entry(root,textvariable=numero2)
entrada2.pack()
aceptar = Button(root,text="Calcular",command=my_function)
aceptar.pack()
root.mainloop()

I'm working on simple graphic interfaces in Python. I`m using the tkinter library to practice with.

The form generated is quite simple, it just consist of two inputs and a button that calls the function: my_function.

I have troubles calling that function because the attribute "command" does not allows any parameter, but my_function requires two that are given by the inputs of the form.

Then, the idea is calling several functions inside my_function and return in a label a calculated_property.

Can you give me any solution?

Thank U so much!

BatuDog88
  • 3
  • 3
  • possible duplicate of [How can I pass arguments to Tkinter button's callback command?](http://stackoverflow.com/questions/6922621/how-can-i-pass-arguments-to-tkinter-buttons-callback-command) and [passing argument in python Tkinter button command](http://stackoverflow.com/questions/6920302/passing-argument-in-python-tkinter-button-command) – fredtantini Dec 11 '14 at 19:37

1 Answers1

1

You can simply use a lambda function to pass the arguments:

aceptar = Button(root,text="Calcular", command=lambda: my_function(arg1, arg2))

This code is equivalent to doing:

def func():
    my_function(arg1, arg2)
aceptar = Button(root,text="Calcular", command=func)

except that the function is created inline.