Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

tkinter, button that adds its label to Entry

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading