ทุก Widget ใน Tkinter รองรับเมธอด .cget('option') เพื่อดึงค่าการตั้งค่า เช่น ข้อความ (text) ของปุ่ม
ตัวอย่างโค้ด
# 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")
# Create a button
button = ttk.Button(win, text="My Button")
button.pack()
# Get the text of Button
mytext = button.cget('text')
# Create a label to print the button information
Label(win, text=mytext, font=('Helvetica 20 bold')).pack(pady=20)
win.mainloop()
ผลลัพธ์
โปรแกรมแสดงปุ่มและ Label ที่แสดงข้อความของปุ่ม ("My Button")
