Python 3 Tkinter Bind Keyboard Key to Button GUI Desktop App Full Project For Beginners



#Import tkinter library
from tkinter import *
from tkinter import ttk

#Create an instance of Tkinter frame or window
win = Tk()

#Set the geometry of tkinter frame
def callback():
   Label(win, text="Hello World!", font=('Georgia 20 bold')).pack(pady=4)

#Create a Label and a Button widget
btn = ttk.Button(win, text="Press Enter to Show a Message", command= callback)

win.bind('<Return>',lambda event:callback())


Leave a Reply