Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธี Clear เนื้อหา Tkinter Text Widget


ภาพรวม

Tkinter Text Widget ใช้เพิ่ม Text Writer ในแอป มี Attribute และ Property มากมาย Extend ฟังก์ชัน Text Editor เพื่อลบ Input Content ใช้เมธอด delete("start", "end")

ตัวอย่างโค้ด

# Import the tkinter library
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
# Set the geometry
win.geometry("600x250")
# Define a function to clear the input text
def clearToTextInput():
    my_text.delete("1.0", "end")
# Create a text widget
my_text = Text(win, height=10)
my_text.pack()
# Create a Button
btn = Button(win, height=1, width=10, text="Clear", command=clearToTextInput)
btn.pack()
# Display the window without pressing key
win.mainloop()

ผลลัพธ์

รันโค้ดจะสร้าง Text Widget และ Button ใช้ Clear Input Text

วิธี Clear เนื้อหา Tkinter Text Widget

คลิก "Clear" จะ Clear Input Text