특정 애플리케이션의 경우 정의된 버튼을 사용하여 여러 작업을 수행하려면 bind(Button, callback)를 사용할 수 있습니다. 버튼과 이벤트를 함께 바인딩하여 애플리케이션에서 이벤트 실행을 예약하는 메서드입니다.
단일
예
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the window
win.geometry("700x350")
def change_bgcolor(e):
label.config(background="#adad12")
def change_fgcolor(e):
label.config(foreground="white")
# Add a Label widget
label = Label(win, text="Hello World! Welcome to Tutorialspoint", font=('Georgia 19 italic'))
label.pack(pady=30)
# Add Buttons to trigger the event
b1 = ttk.Button(win, text="Button-1")
b1.pack()
# Bind the events
for b in [b1]:
b.bind("<Enter>", change_bgcolor)
b.bind("<Leave>", change_fgcolor)
win.mainloop() 출력
위의 코드를 실행하면 버튼이 포함된 창이 표시됩니다.

버튼 위로 마우스를 가져가면 레이블의 배경색이 변경됩니다. 버튼을 떠나면 레이블 위젯의 글꼴 색상이 변경됩니다.
