Search code examples
pythontkinterlabeltkinter-entry

How to get input from Entry and set it as the text in a Label


how do I get the Input from an Entry widget and set it as the text in a label widget.

I have tried the following:

l_one = Label(window, text= lambda: self.entry_1.get())
l_one.grid(column = 0, row = 0)

To be honest, I didn't think it would work but it was all I could think of.


Solution

  • If you want a label to have exactly what was input in an Entry widget, you can have them share the same value for the textvariable attribute:

    theVariable = tk.StringVar()
    tk.Entry(..., textvariable=theVariable)
    tk.Label(..., textvariable=theVariable)
    

    With that, you don't have to do anything else -- no callbacks, no bindings, no buttons. Whenever you type in the entry widget then the label will automatically update.