วิดเจ็ตปุ่มเป็นวิธีการสื่อสารผ่านฟังก์ชันที่มีอยู่ทั้งหมดของแอปพลิเคชัน เราสามารถดำเนินการบางอย่างได้ด้วยความช่วยเหลือของปุ่มที่ห่อหุ้มฟังก์ชันและวัตถุ อย่างไรก็ตาม อาจมีบางกรณีที่เราต้องการดำเนินการหลายอย่างด้วยปุ่มเดียว ซึ่งสามารถทำได้โดยการกำหนดฟังก์ชันแลมบ์ดาที่กำหนดเป้าหมายหลายเหตุการณ์หรือการเรียกกลับในแอปพลิเคชัน
ตัวอย่าง
ในตัวอย่างนี้ เราจะเพิ่มหลายเหตุการณ์ให้กับปุ่มใดปุ่มหนึ่ง
#Import the Tkinter Library
from tkinter import *
#Create an instance of Tkinter Frame
win = Tk()
#Set the geometry of window
win.geometry("700x350")
#Define functions
def display_msg():
label.config(text="Top List of Programming Language")
def show_list():
listbox= Listbox(win, height=10, width= 15, bg= 'grey', activestyle= 'dotbox',font='aerial')
listbox.insert(1,"Go")
listbox.insert(1,"Java")
listbox.insert(1,"Python")
listbox.insert(1,"C++")
listbox.insert(1,"Ruby")
listbox.pack()
button.destroy()
#Create a Label widget to display the message
label= Label(win, text= "", font= ('aerial 18 bold'))
label.pack(pady= 20)
#Define a Button widget
button= Button(win, text= "Click Here",command= lambda:[display_msg(), show_list()])
button.pack()
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีปุ่ม

เมื่อเราคลิกปุ่ม มันจะทำงานสองอย่างพร้อมกัน มันจะแสดงหน้าต่างที่มีวิดเจ็ตป้ายกำกับและรายการสตริง
