Created
April 9, 2024 21:59
-
-
Save vigilantPotato/7a221b6946da46235eff740e9a474bd5 to your computer and use it in GitHub Desktop.
How to get the text in entry widget by Enter key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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