python tkinter.Text里面字体大小颜色怎么设置呢?

如题。

img


这里面字体的大小和颜色还有背景色怎么设置呢?谢谢。越简单越好。

字体设置要导入 tkinter.font
颜色设置在config方法中用参数foreground (背景色则用background)
测试代码如下:

import tkinter as tk
import tkinter.font as tf

win = tk.Tk()
win.geometry('400x300')
win.title('测试')
 
te1xt = tk.Text(win,width=270,height=50)
te1xt.place(x=0,y=0)
 
font1 = tf.Font(family='微软雅黑',size=24)
te1xt.insert(0.0,'测试abcd')
te1xt.config(font=font1,foreground='red')

win.mainloop()

img