Tkinter Labels ใช้เพื่อสร้างและแสดงข้อความหรือรูปภาพบนหน้าต่าง มีส่วนประกอบและฟังก์ชันหลายอย่างที่สามารถใช้ปรับแต่งข้อมูลฉลากได้ เช่น ฟอนต์แฟมิลี่ แพ็ดดิ้ง ความกว้าง ความสูง ฯลฯ เพื่อให้ได้ข้อความป้ายกำกับบนหน้าต่าง เราสามารถเขียนค่าสำหรับข้อความที่ต้องการได้ ปรากฏบนหน้าต่าง
ตัวอย่าง
#Import the required library
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Define the geometry of the window
win.geometry("600x250")
#Create a Label with Text
my_text= Label(win, text= "This is a New Line Text", font=('Helvetica bold', 16))
my_text.pack(pady=15)
#Print the label text
print(my_text['text'])
win.mainloop() ผลลัพธ์
โค้ดด้านบนจะแสดงป้ายกำกับ "This is a New Line Text" ซึ่งสามารถพิมพ์ได้ด้วยฟังก์ชันการพิมพ์
