Search code examples
pythonpython-3.xtkintertkinter-entry

Python Entry Button Submit issues


Currently with the below code I seem to be getting a weird issue as well cant seem to get the value of refreshtoken when I click the submit button. I do get the print for word but for refreshtoken I receive .!entry in the Console.

def getCommand(r):
print('word')
print(r)


tokenWindowFrame = Tk()
tokenWindowFrame.title("Add Character")
refreshLabel = ttk.Label(tokenWindowFrame, text="Refresh Token : ")
refreshLabel.grid(row=1,column=1)
refreshToken = ttk.Entry(tokenWindowFrame, width = 50)
refreshToken.grid(row=1,column=2)
button = ttk.Button(tokenWindowFrame, text = "Submit", command=lambda 
r=refreshToken: getCommand(r))
button.grid(row=3,column=2)



tokenWindowFrame.mainloop()

Solution

  • I ended up having to change this line button = ttk.Button(tokenWindowFrame, text = "Submit", command=lambda r=refreshToken: getCommand(r)) To : button = ttk.Button(tokenWindowFrame, text = "Submit", command=lambda r=refreshToken: getCommand(r.get()))

    The r.get() is what I was missing. As both print(r.get()) would not work in the Function.