สมมติว่าเราได้สร้างวิดเจ็ตรายการและเราต้องการรับค่าของมัน ในกรณีนี้ เราสามารถใช้ .get() กระบวนการ. มันจับคู่วัตถุอินพุตเป็นตัวแปรซึ่งสามารถใช้เพิ่มเติมเพื่อพิมพ์หรือแสดงค่าที่ป้อน
ตัวอย่าง
ในตัวอย่างนี้ เราจะสร้างแอปพลิเคชันที่จะแสดงข้อความป้อนเข้าอย่างละเอียดในวิดเจ็ตป้ายกำกับ
#Import tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
win.geometry("750x250")
def get_value():
e_text=entry.get()
Label(win, text=e_text, font= ('Century 15 bold')).pack(pady=20)
#Create an Entry Widget
entry= ttk.Entry(win,font=('Century 12'),width=40)
entry.pack(pady= 30)
#Create a button to display the text of entry widget
button= ttk.Button(win, text="Enter", command= get_value)
button.pack()
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีวิดเจ็ตรายการและปุ่ม
ในผลลัพธ์ที่กำหนด หากเราจะคลิกปุ่ม Enter มันจะเลียนแบบค่าอินพุตจากวิดเจ็ตรายการ
