0

so i made a button on my tkinter-field,witch would return an entry in an field,witch I built prior,thanks for that,anyway it doesn' return anything,here is a snippet of my source code

entry = Entry()
entry.pack()
def get_entry():
    entry.get()
schaltf2 = tkinter.Button(root, text="submit", width=20, command=get_entry())
schaltf2.pack(side="bottom")

could maybe anyone help me,that would be very nice,thank you!:)

  • You assign the result of a call to "get_entry" to "command" argument. Remove the parentheses to assign the function itself. – Michael Butscher Jan 16 '22 at 13:24
  • *" it doesn' return anything"* because the function does not have a `return` statement. Even it returns something, it is discarded if it is called by a button click callback. – acw1668 Jan 16 '22 at 14:45

1 Answers1

0

this is because first you have to do a StringVar() object to get the value, so to initialize the entry you have to do:

string_var = tkinter.StringVar(root)
entry = tkinter.Entry(root, textvariable=string_var)

and in the function get_entry() you have to return entry.get() so you would do:

>>> def get_entry():
...    return entry.get()
XxJames07-
  • 1,833
  • 1
  • 4
  • 17