i want to make a button on which \'2\' is written .... now when anyone click it , it will show the number \'2\' in the entry box... the error is: before clicking , it is a
Pass a function (used lambda in the following code) instead of return value of the function.
from tkinter import *
root = Tk()
e1 = Entry(root)
e1.pack()
def add(x):
e1.insert(INSERT, x)
a = Button(root, text='2', command=lambda: add(2))
a.pack()
root.mainloop()
In addition to that, extract Entry creation code out of the add function. Otherwise entry are create every time when the button is clicked.