เหตุการณ์ Tkinter ถูกดำเนินการในรันไทม์ และเมื่อเราผูกเหตุการณ์เหล่านี้กับปุ่มหรือคีย์ แล้วเราจะได้รับการเข้าถึงเพื่อจัดลำดับความสำคัญของเหตุการณ์ในแอปพลิเคชัน
เพื่อผูกคีย์ <Enter> กับเหตุการณ์ในหน้าต่าง Tkinter เราสามารถใช้ bind('
ตัวอย่าง
# Import the required libraries
from tkinter import *
from PIL import Image, ImageTk
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the window
win.geometry("700x350")
def show_msg(event):
label["text"] = "Sale Up to 50% Off!"
# Create a label widget
label = Label(win, text="Press Enter Key", font="TkMenuFont 20")
label.pack(pady=30)
# Bind the Enter Key to the window
win.bind('', show_msg)
win.mainloop()
ผลลัพธ์
การรันโค้ดด้านบนจะแสดงหน้าต่างที่จะทริกเกอร์เหตุการณ์เมื่อเรากดปุ่ม <Enter>

ตอนนี้ กดปุ่ม <Enter> และสังเกตผลลัพธ์
