Tkinter เป็นไลบรารี Python ที่ใช้ในการสร้างและพัฒนาแอพพลิเคชั่นที่ทำงานบน GUI Tkinter มีวิดเจ็ตที่สามารถใช้สำหรับสร้างการนำเสนอแอปพลิเคชันด้วยภาพและการใช้งาน
สมมติว่าเราได้กำหนดวิดเจ็ตบางอย่างในแอปพลิเคชันของเรา หากเราต้องการรับชื่อวิดเจ็ตในเหตุการณ์ สามารถทำได้โดยใช้ event.widget["text"] คีย์เวิร์ดภายในฟังก์ชัน เราสามารถพิมพ์ชื่อได้โดยใช้ใน print() ฟังก์ชัน
ตัวอย่าง
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the tkinter window
win.geometry("700x300")
# Define a function to delete the shape
def on_click():
print (win.winfo_children())
# Create a canvas widget
canvas=Canvas(win, width=500, height=300)
canvas.pack()
# Create a button to delete the button
Button(win, text="Click", command=on_click).pack()
win.mainloop() ผลลัพธ์
หากเราเรียกใช้โค้ดข้างต้น จะแสดงหน้าต่างพร้อมปุ่ม

หากเราคลิกปุ่ม ผลลัพธ์จะแสดงชื่อของวิดเจ็ตบนหน้าจอ
[<tkinter.Canvas object .!canvas>, <tkinter.Button object .!button>]