Search code examples
python-3.xtkintertkinter-entry

Entry.get() returns nothing tkinter - python 3.4


In the following code I am trying to open a new window by clicking on a button. One of the necessary arguments passed to the function that opens the new window is a string taken from an entry.get() method but the method returns nothing. Why is this happening?

window = tk.Toplevel(self)
doc = Document(self.entry_filepath.get())

entry_doc_id = tk.Entry(window, width=20)
entry_doc_id.grid(sticky=W+E+N+S, row=0, column=1, columnspan=3)

button_country_views = tk.Button(window, text="Views by country", command=partial(self.display_views_by_country, doc, entry_doc_id.get()), width=25)                                                               
button_country_views.grid(row=1, column=1, sticky=W+E+N+S)

Solution

  • Entry.get() is called only once (by partial) when you start program.

    You can use lambda in place of partial

    command=lambda:self.display_views_by_country(doc, entry_doc_id.get())
    

    Or you can define function and assign it to command

    def my_function():
        self.display_views_by_country(doc, entry_doc_id.get())
    
    command=my_function