Tkinter 이벤트는 특정 작업이나 작업을 수행해야 하는 모든 응용 프로그램에 매우 유용합니다. Tkinter에서 이벤트는 일반적으로 특정 이벤트에 대한 코드와 논리를 포함하는 함수를 정의하여 생성됩니다. 이벤트를 호출하기 위해 일반적으로 일부 키 또는 버튼 위젯으로 이벤트를 바인딩합니다. bind 함수는 두 개의 매개변수를 취합니다. ('
다음 예에서 동일한 접근 방식을 사용하여
예시
# Import the required libraries
from tkinter import *
from tkinter import messagebox
# Create an instance of tkinter frame
win= Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Define a function to show the popup message
def show_msg(e):
messagebox.showinfo("Message","Hey There! I hope you are doing well.")
# Add an optional Label widget
Label(win, text = "Admin Has Sent You a Message. " "Press <Shift+Tab> to View the Message.", font = ('Aerial 15')).pack(pady= 40)
# Bind the Shift+Tab key with the event
win.bind('<Shift-Tab>', lambda e: show_msg(e))
win.mainloop() 출력
위의 프로그램을 실행하면 레이블 위젯이 포함된 창이 표시됩니다.
