Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created April 9, 2024 21:59
Show Gist options
  • Select an option

  • Save vigilantPotato/7a221b6946da46235eff740e9a474bd5 to your computer and use it in GitHub Desktop.

Select an option

Save vigilantPotato/7a221b6946da46235eff740e9a474bd5 to your computer and use it in GitHub Desktop.
How to get the text in entry widget by Enter key
import ctypes
import tkinter
def input(event):
l["text"] = e1.get() #set label text
e1.delete(0, tkinter.END) #delete entry
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
#Label
l = tkinter.Label(root, width=15, bg="lightblue")
l.pack(pady=3)
#Entry
e1 = tkinter.Entry(root, bd=5)
e1.bind("<Return>", input) #bind Retun key
e1.pack(padx=3)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment