如何在不知道元件字體系列/大小的情況下更改 Tkinter 元件的字型樣式?
Tkinter 元件支援屬性,如字體系列與字型大小,可以使用屬性font(‘Font-Family’, font-size)指定。
示例
在以下示例中,我們建立了一個文字標籤,可透過將字體系列定義為“Times New Roman”和字型大小定義為“20”來進行配置。
#Import the tkinter library
from tkinter import *
#Create an instance of tkinter frame
win = Tk()
#Set the geometry
win.geometry("650x250")
#Add a text label and add the font property to it
label= Label(win, text= "This is a New Text", font=('Times New Roman bold',20))
label.pack(padx=10, pady=10)
win.mainloop()輸出
執行上述程式碼將顯示包含文字的視窗或框架,

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP