เราสามารถใช้ Tkinter ข้อความ วิดเจ็ตเพื่อแทรกข้อความ แสดงข้อมูล และรับผลลัพธ์จาก ข้อความ วิดเจ็ต ในการรับข้อมูลของผู้ใช้เป็น ข้อความ วิดเจ็ต เราต้องใช้ get() กระบวนการ. มาดูตัวอย่างกันว่ามันทำงานอย่างไร
ตัวอย่าง
# Import the required library
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win=Tk()
# Set the geometry
win.geometry("700x350")
def get_input():
label.config(text=""+text.get(1.0, "end-1c"))
# Add a text widget
text=Text(win, width=80, height=15)
text.insert(END, "")
text.pack()
# Create a button to get the text input
b=ttk.Button(win, text="Print", command=get_input)
b.pack()
# Create a Label widget
label=Label(win, text="", font=('Calibri 15'))
label.pack()
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มี ข้อความ วิดเจ็ตและปุ่มสำหรับพิมพ์และแสดงผล เมื่อคุณพิมพ์บางอย่างในวิดเจ็ตข้อความและคลิกที่ "พิมพ์" ปุ่มจะแสดงผลลัพธ์ที่ด้านล่างใน ป้ายกำกับ วิดเจ็ต
