Widget Label ใช้แสดงข้อความและภาพในแอปพลิเคชัน ขนาดของ Label ขึ้นอยู่กับหลายปัจจัย เช่น ความกว้าง ความสูง และขนาดฟอนต์ของข้อความ ความสูงและความกว้างกำหนดว่า Label จะปรากฏอย่างไรในหน้าต่าง
เพื่อตั้งค่าความกว้างของ Label ให้ประกาศ Label widget ด้วยตัวแปร การสร้าง Label พร้อมตัวแปรช่วยให้ผู้ใช้เพิ่ม/แก้ไขคุณสมบัติของ Label ได้
ตัวอย่าง
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add a Label widget
label=Label(win, text="A Label widget is used to display text " "and images in an application.", font=('Times 14'), width=100)
label.pack()
win.mainloop()ผลลัพธ์
การรันโค้ดจะแสดงหน้าต่างที่มี Label text พร้อมความกว้าง
