I\'ve looked at several posts on stackOverflow that explain the answer but no matter which I use, I never can get the string from my entry widget; it just detects a string o
Please read and follow this SO help page. Your code is missing lines needed to run and has lines that are extraneous to your question. It is also missing indentation.
Your problem is that you call userInput.get()
just once, while creating the button, before the user can enter anything. At that time, its value is indeed ''
. You must call it within the button command function, which is called each time the button is pressed.
Here is a minimal complete example that both runs and works.
import tkinter as tk
root = tk.Tk()
user_input = tk.StringVar(root)
answer = 3
def verify():
print(int(user_input.get()) == answer) # calling get() here!
entry = tk.Entry(root, textvariable=user_input)
entry.pack()
check = tk.Button(root, text='check 3', command=verify)
check.pack()
root.mainloop()