ในการเปลี่ยนพฤติกรรมเริ่มต้นของวิดเจ็ต tkinter เรามักจะแทนที่ option_add() กระบวนการ. คุณสมบัติและค่าที่ส่งไปยัง option_add() วิธีจะแสดงการเปลี่ยนแปลงในวิดเจ็ตทั้งหมดในแอปพลิเคชัน ดังนั้น การเปลี่ยนแบบอักษรเริ่มต้นจะส่งผลต่อแบบอักษรสำหรับวิดเจ็ตทั้งหมดที่กำหนดไว้ในแอปพลิเคชัน
ตัวอย่าง
ที่นี่ เราจะส่งพารามิเตอร์สองตัวไปยังเมธอด option_add() นั่นคือ option_add("*font", "font-family font-size font-style font-orientation")
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the geometry of frame
win.geometry("600x400")
#Change the default Font that will affect in all the widgets
win.option_add( "*font", "lucida 20 bold italic" )
win.resizable(False, False)
#Create a Label
Label(win, text="This is a New Line").pack()
Button(win, text="Button-1", width=10).pack()
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดข้างต้นจะตั้งค่าแบบอักษรเริ่มต้นเป็น "lucida 20 ตัวหนา ตัวเอียง" สำหรับวิดเจ็ตทั้งหมดที่ใช้ข้อมูลที่เป็นข้อความ

ตอนนี้ กลับไปที่โปรแกรม ลบบรรทัดต่อไปนี้ แล้วเรียกใช้อีกครั้ง
win.option_add( "*font", "lucida 20 bold italic" )
ข้อความจะปรากฏในแบบอักษรเริ่มต้น -
