특정 응용 프로그램에 대해 버튼이나 키를 누를 때마다 함수를 호출하려고 한다고 가정해 보겠습니다. bind('을 사용하여 버튼이나 키로 작업을 포함하는 함수를 바인딩할 수 있습니다. ) 방법. 여기에서 호출해야 하는 이벤트나 함수에 모든 키를 바인딩할 수 있습니다.
예시
이 예에서는 버튼을 클릭할 때마다 대화 상자를 여는 함수를 만들었습니다.
#Import the required libraries
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
#Create an instance of Tkinter Frame
win = Tk()
#Set the geometry of Tkinter Frame
win.geometry("700x350")
#Define a function for opening the Dialog box
def open_prompt():
messagebox.showinfo("Message", "Click Okay to Proceed")
#Create a Label widget
Label(win, text= "Click to Open the MessageBox").pack(pady=15)
#Create a Button for opening a dialog Box
ttk.Button(win, text= "Open", command= open_prompt).pack()
win.mainloop() 출력
위의 코드를 실행하면 레이블과 버튼이 포함된 창이 표시됩니다.

"열기" 버튼을 클릭하면 대화 상자를 여는 함수를 호출합니다.
