0

I am trying to make a gui for a basic dbms project and while tkinter seems pretty easy for the most part i am unable to get how to use Entry to actually take the input and store it to use later (like an if condition or something) eg:

root = Tk()
label = Label(root,text="Testing")
label.grid(row=0)
entry = Entry(root)
entry.grid(row=0,column=1)

Now what i want to do is use the value/word i just wrote in the entry field to say just print it out on for example the console.

I thought we could just write

print(entry)

but that justs prints some random decimal on the console, ideally id like to store the value in some variable (if its not possible to use just "entry") so i can also use it in if conditions etc

I am using python 3

1
  • Have you read through the documentation on the Entry widget? The methods for retrieving the data are documented. Commented Apr 14, 2017 at 14:29

3 Answers 3

1

you mean you want to show some data in entry?

you may just do it like this:

v = StringVar()
e = Entry(master, textvariable=v)
e.pack()

v.set("a default value")
s = e.get()

you can just set the value of "v", for example the Entry show " a default value" string. And you can get the value use "get" method.

Sign up to request clarification or add additional context in comments.

4 Comments

i am trying to combine it by using it such that i press a button and it prints the so i added s=v.get() button=Button(text="enter",command=print(s)) button.grid(row=1) but that did not print anything
button=Button(text="enter",command=print_fun), and in print_fun you call print s
@hankyman i know its trivail but i dont get how to do that, the function cannot have any arguments cause command= thing does not take function name with the brackets, as in i cant do print_fun(s): print(s) button=Button(text="enter",command=print_fun) so how would i write it ?
func = (lambda x = s : print(x)) button=Button(text="enter",command=func) you just pass the argument to the func
1

you have to retrieve the value:

s=entry.get()
print(s)

Comments

1

By printing entry you are printing not what is in the entry, but the actual entry itself. You need to use entry.get() to grab the contents of the entry.

print(entry.get())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.