โดย Jom07 » 21/02/2018 5:35 pm
การใช้งาน Python GUI (Tkinter) :Label widget (วิดเจ็ตป้ายกำกับ) เป็นการสร้างหน้าต่าง กำหนดข้อความ และ การจัดข้อความต่างๆ เช่น จัดให้อยู่ ซ้าย หรือขวา
ตัวอย่าง
โค้ด
โค้ด: เลือกทั้งหมด
from tkinter import *
root = Tk()
root.option_add("*Font", "consolas 10")
Label(root, text="Mind", bg="light green").pack(anchor=W)
Label(root, text="mindphp", bg="blue").pack(fill=X)
Label(root, text="aaaaaaaaaa\na", bg="gold").pack(anchor=E)
Label(root, text="b\nb", bg="orange", wraplength=10, justify=RIGHT).pack(fill=X)
Label(root, text="c\nc", bg="deep sky blue", wraplength=10, justify=LEFT).pack(fill=X)
Label(root, text="d\nd", bg="hot pink", wraplength=10).pack(fill=X)
root.mainloop()
ผลรัน
ทำให้เราจัดข้อความได้ง่ายมากขึ้น
การใช้งาน Python GUI (Tkinter) :Label widget (วิดเจ็ตป้ายกำกับ) เป็นการสร้างหน้าต่าง กำหนดข้อความ และ การจัดข้อความต่างๆ เช่น จัดให้อยู่ ซ้าย หรือขวา
[b]ตัวอย่าง[/b]
[b]โค้ด[/b]
[code]from tkinter import *
root = Tk()
root.option_add("*Font", "consolas 10")
Label(root, text="Mind", bg="light green").pack(anchor=W)
Label(root, text="mindphp", bg="blue").pack(fill=X)
Label(root, text="aaaaaaaaaa\na", bg="gold").pack(anchor=E)
Label(root, text="b\nb", bg="orange", wraplength=10, justify=RIGHT).pack(fill=X)
Label(root, text="c\nc", bg="deep sky blue", wraplength=10, justify=LEFT).pack(fill=X)
Label(root, text="d\nd", bg="hot pink", wraplength=10).pack(fill=X)
root.mainloop()
[/code]
[b]ผลรัน[/b]
[img]http://snap.mindphp.com/index.php?view=2018Feb21_5a8d485bc5f3e[/img]
ทำให้เราจัดข้อความได้ง่ายมากขึ้น