Pardon me if this is a bad question, I’m still learning python. I am trying to get my buttons label to show up on my entry by clicking the button, but it is showing up as !button(button number). How can I fix this? Here is a MWE:
from tkinter import*
def buttonEntry(button,rowNumber,columnNumber):
def clickEntry():
mainEntry.insert(0,button)
button=Button(root,text=button,command=clickEntry)
button.grid(row=rowNumber,column=columnNumber)
root=Tk()
mainEntry=Entry(root)
mainEntry.grid(row=0,column=0)
buttonEntry("Label",1,0)
root.mainloop()
I tried moving the definition around, and looked up the problem on the internet, including reviewing the list of similar question. I am hoping to have the button variable show up in the mainEntry. Thank you
>Solution :
The problem is your reuse of the name button. You do pass it in as a parameter, but then you overwrite it with the Button object, and that’s what gets inserted. Just use different names for those two things.