虽然有点“作弊”的味道,但是的确可以运行。
import idlelib.colorizer as idc
import idlelib.percolator as idp
import tkinter as tk
root=tk.Tk()
root.title('代码高亮测试')
text=tk.Text(root,font=('宋体',25))
text.pack(fill=tk.BOTH)
idc.color_config(text)
text.focus_set()
p = idp.Percolator(text)
d = idc.ColorDelegator()
p.insertfilter(d)
root.mainloop()
呵呵呵,好不好玩?