Các sự kiện Tkinter được thực thi trong thời gian chạy và khi chúng tôi liên kết các sự kiện này bằng một nút hoặc khóa, thì chúng tôi sẽ có quyền truy cập để ưu tiên sự kiện trong ứng dụng.
Để liên kết khóa
Ví dụ
# 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('<Return>', show_msg) win.mainloop()
Đầu ra
Chạy đoạn mã trên sẽ hiển thị một cửa sổ sẽ kích hoạt sự kiện khi chúng ta nhấn phím
Bây giờ, nhấn phím