How to convert an entry () to input ()?

1

Hi, I'm doing a program in tkinter that deals with a list to which you can add and remove what the user enters. For the user to add something, I need that when I press enter the information found in entry()" is saved and a code is executed. How can I do it?

The Code:

import tkinter as tk



def agregar():
    bA.place_forget()
    bR.place_forget()

    label = tk.Label(ventana, text = "Que desea agregar?", width = 31, fg = "black")
    label.place(x = 40, y = 100)

    var_e = tk.StringVar()

    ent = tk.Entry(ventana, textvariable = var_e, width = 42, fg = "black")
    ent.place(x = 20, y = 130)

def remover():
    pass



ventana = tk.Tk()
ventana.title("Lista")
ventana.geometry('300x250')

var_L = tk.StringVar()

Lista = tk.Label(ventana, textvariable = var_L, width = 31, bg = "white", bd = 20)
Lista.place(x = 20, y = 32)


bA = tk.Button(ventana, text = "Agregar", width = 15, fg = "black", command = agregar)
bA.place(x = 20, y = 120)

bR = tk.Button(ventana, text = "Remover", width = 15, fg = "black", command = remover)         
bR.place(x = 165, y = 120)

bS = tk.Button(ventana, text = "Salir", width = 7, fg = "black", command = quit)
bS.place(x = 120, y = 200)


ventana.mainloop()
    
asked by ElAlien123 25.01.2018 в 15:43
source

1 answer

0

What you can do is the following:

first you create the routine that will react to <Enter> of the user, for example this will print the entered text by console:

def ent_get(event):
   print(event.widget.get())

Then you simply have to "listen" to a new event when the user presses <Enter> and invoke our routine, this we will do in agregar() after having created the Entry ent

ent.bind('<Return>', ent_get)
    
answered by 25.01.2018 / 16:10
source