如何在不知道组件字体系列/大小的情况下更改 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