[Tkinter] how to activate Enter key in text box - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] how to activate Enter key in text box (/thread-30362.html) |
how to activate Enter key in text box - astral_travel - Oct-17-2020 Hi ! i tried the following: import tkinter as tk window = tk.Tk() greeting = tk.Label(text="hello everyone \n what's up") greeting.pack() entry = tk.Entry(window) name = entry.get() entry.pack() text_box = tk.Label(name) text_box.pack() print(name) window.mainloop()and it shows the window and everything, but when i put in text and press Enter, nothing happens... i have a code that gets it done with a button, like - a submit button... - but what i wanna do is get the input by pressing the Enter key directly from the text box... do you know what i should do ? RE: how to activate Enter key in text box - deanhystad - Oct-17-2020 Bind a function to an event. I think there is a special key press event for the enter key RE: how to activate Enter key in text box - Yoriz - Oct-17-2020 import tkinter as tk window = tk.Tk() greeting = tk.Label(text="hello everyone \n what's up") greeting.pack() entry = tk.Entry(window) entry.pack() text_box = tk.Label('') text_box.pack() def on_entry(event): text_box['text'] = name = entry.get() print(name) entry.bind('<Return>', on_entry) window.mainloop() RE: how to activate Enter key in text box - astral_travel - Oct-17-2020 wow !! that's awesome ! thank you so much !! and so simple ah ! |