from tkinter import *
import tkinter.colorchooser
root =Tk()
root.title("字体样式设置" )
root.geometry("300x300")
Label(root,text="文本样式设置:").place(x=30,y=10)
txt=Text(root,font=('宋体',12))
txt.place(x=30,y=30,height=140,width=260)
Label(root,text="字体大小:").place(x=30,y=180)
Label(root,text="字体颜色:").place(x=30,y=210)
etr1=Entry(root)
etr1.place(x=90,y=180)
etr2=Entry(root,width=10)
etr2.place(x=90,y=210)
def xz():
color=tkinter.colorchooser.askcolor()
colorstr=str(color)
etr2.delete(0,"end")
etr2.insert(0,colorstr[-9:-2])
etr2.config(fg=colorstr[-9:-2])
Button(root, text='颜色选择',width=7,font=("黑体",11),command=xz).place(x=165,y=210)
#*******************GUI*******************#
def set():
size_str=etr1.get()
color_str=etr2.get()
if size_str.isdigit():
txt.config(font=("宋体",int(size_str)))
if color_str.startswith("#") and len(color_str)==7:
txt.config(fg=color_str)
Button(root, text="设置",width=15,font=("黑体",11),command=set).place(x=85,y=250)
#*******************End*******************#
root.mainloop()