如何为 Tkinter 中的文本设置字体?
Tkinter 有许多用于在窗口部件中提供不同特性的内置方法和函数。我们可以使用 font(‘font-family’,font-size, ‘style’) 属性自定义 Tkinter 应用程序中文本窗口部件的字体属性。元组可以在 Text 构造器中声明。
示例
Let us have a look at the following example where we will create a text widget with a customized font property.
#Import tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
win.geometry("750x250")
#Define a text widget with font-property
text= Text(win, height=15, font=('Times New Roman',17,'bold'))
text.insert(INSERT, "Hey Folks!, Welcome to TutorialsPoint!")
text.pack()
win.mainloop()输出
运行上述代码将显示一个包含文本窗口部件的窗口。可以使用 font 属性自定义写在文本窗口部件中的文本。

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP