Why is Tkinter Entry’s get function returning nothing?

It looks like you may be confused as to when commands are run. In your example, you are calling the get method before the GUI has a chance to be displayed on the screen (which happens after you call mainloop.

Try adding a button that calls the get method. This is much easier if you write your application as a class. For example:

import tkinter as tk

class SampleApp(tk.Tk):
    def __init__(self):
        self.entry = tk.Entry(self)
        self.button = tk.Button(self, text="Get", command=self.on_button)

    def on_button(self):

app = SampleApp()

Run the program, type into the entry widget, then click on the button.

Leave a Comment