With this below Python code, I wanted to
- type "exit"
- press "enter" key from keyboard
- Close the tkinter window
But post typing "exit" and pressing "Enter" key from keyboard, the "tk window" is not closing.
And the Code is:
import tkinter as tk
window = tk.Tk()
greeting = tk.Label(text = "Test Tk window Frame")
user_input = tk.Text()
user_input.pack()
greeting.pack()
def chat(event=None):
inputmsg = user_input.get(tk.END)
if inputmsg is None or inputmsg == "":
return None
if inputmsg.lower() == "exit"
inputmsg.bind('<Return>', lambda e: window.destroy()) # NOT Working
#window.destroy() # Not Working
return None
user_input.bind("<Return>", chat) # NOT Working out
window.mainloop()
My intention is to Bind ONLY RETURN KEY and not with a Button. As I'm new to Python with tkinter, Can anyone please share any thought/ ref on this?
Thank you.