ภาพรวม
ใน Tkinter สร้าง Text Widgets ด้วย Attributes และ Packages แต่ขณะสร้าง GUI App บางครั้งต้อง Capture Input จาก Text Widget รับ Input จาก User ใน Text Widget ด้วยเมธอด .get() ระบุ Input Range เริ่มจาก 1.0 ถึง END แสดงตัวอักษรตั้งแต่ต้นจนจบ
ตัวอย่างโค้ด
# Import tkinter library
from tkinter import *
# Create an instance of tkinter window or frame
win = Tk()
win.geometry("700x300")
def get_input():
value = my_text_box.get("1.0", "end-1c")
print(value)
# Creating a text box widget
my_text_box = Text(win, height=5, width=40)
my_text_box.pack()
# Create a button for Comment
comment = Button(win, height=5, width=10, text="Comment", command=lambda: get_input())
comment.pack()
win.mainloop()
ผลลัพธ์
รันโค้ดจะแสดง Textbox รับ Input จาก User และ Print Output บน Console
