วิดเจ็ตข้อความ Tkinter เป็นวิดเจ็ตอินพุตที่รองรับการป้อนข้อมูลของผู้ใช้หลายบรรทัด เป็นที่รู้จักกันว่า Text Editor ซึ่งอนุญาตให้ผู้ใช้เขียนเนื้อหาและข้อมูลในนั้น เนื้อหาของวิดเจ็ตข้อความสามารถล้างได้โดยการกำหนด ลบ(0, END) สั่งการ. ในทำนองเดียวกัน เราสามารถล้างเนื้อหาได้โดยคลิกที่วิดเจ็ตรายการ ซึ่งสามารถทำได้โดยการผูกฟังก์ชันกับเหตุการณ์การคลิก
ตัวอย่าง
#Import the required libraries
from tkinter import *
#Create an instance of Tkinter Frame
win = Tk()
#Set the geometry of Tkinter Frame
win.geometry("700x250")
#Define a function to clear the content of the text widget
def click(event):
name.configure(state=NORMAL)
name.delete(0, END)
name.unbind('<Button-1>', clicked)
#Create a Label widget
label = Label(win, text= "Enter Your Name", font= ('Helvetica 13 bold'))
label.pack(pady= 10)
#Create an Entry widget
name = Entry(win, width=45)
name.insert(0, 'Enter Your Name Here...')
name.pack(pady=10)
#Bind the Entry widget with Mouse Button to clear the content
clicked = name.bind('<Button-1>', click)
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างพร้อมวิดเจ็ตรายการ

เมื่อเราคลิกช่องรายการ มันจะล้างเนื้อหาโดยอัตโนมัติ
