ให้เราพิจารณากรณีที่เราต้องการเปลี่ยนแบบอักษรเริ่มต้นของแอปพลิเคชัน Tkinter ในการใช้แบบอักษรและตั้งค่าเป็นแบบอักษรเริ่มต้นสำหรับแอปพลิเคชันเฉพาะ เราต้องใช้ option_add(**options) วิธีการที่เราระบุคุณสมบัติ เช่น สีพื้นหลัง แบบอักษร ฯลฯ การเปลี่ยนแปลงที่เกิดขึ้นหลังจากกำหนดวิธีการจะบังคับให้วิดเจ็ตทั้งหมดสืบทอดคุณสมบัติเดียวกัน
ตัวอย่าง
ในสคริปต์ที่กำหนด เราได้ตั้งค่าแบบอักษรเริ่มต้นสำหรับแอปพลิเคชันเพื่อให้สามารถใช้ได้กับวิดเจ็ตทั้งหมดที่กำหนดไว้ในแอปพลิเคชัน
#Import the required libraries
from tkinter import *
#Create an instance of Tkinter frame
win = Tk()
win.geometry("700x350")
#Add fonts for all the widgets
win.option_add("*Font", "aerial")
#Set the font for the Label widget
win.option_add("*Label.Font", "aerial 18 bold")
# Define the backround color for all the idgets
win.option_add("*Background", "bisque")
#Display bunch of widgets
Label(win, text="Label").pack()
Button(win, text="Button").pack()
#Create a Listbox widget
w = Listbox(win)
for i in range(5):
w.insert(i, "item %d" % (i+1))
w.pack()
w = Text(win, width=20, height=10)
w.insert(1.0, "a text widget")
w.pack()
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างพร้อมวิดเจ็ตป้ายกำกับ ปุ่ม กล่องรายการ และวิดเจ็ตข้อความ ในเอาต์พุตที่กำหนด วิดเจ็ตทั้งหมดจะสืบทอดคุณสมบัติเดียวกัน
