trying to print contents of text box after user clicks search button yet nothing printing tkinter

Question:

User inputs text into a text box clicks search and then the text is printed. Right now being printed in the shell is fine as I am still developing this. However, with everything I have read in the docs, what I am doing should work. So I am assuming its something small that I dont see. Please let me know what I am doing wrong.

def save():
   key = entryName.get()
   print(key)

nameField = StringVar()
entryName = Entry(root,textvariable= nameField)
entryName.grid(row=3,column=2)

searchButton = Button(root, text = "Search", command = save())
searchButton.grid(row = 19,column = 2)
Asked By: Christopher Jakob

||

Answers:

The issue seems to be in the line –

searchButton = Button(root, text = "Search", command = save())

You should set the function directly as the value for command argument, not call it and set its return value as argument (which is None , since the function does not return anything) . Example –

searchButton = Button(root, text = "Search", command = save)
Answered By: Anand S Kumar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.