谁能解释如何向 TkinterText小部件添加语法突出显示?
每当程序找到匹配的单词时,它就会按照我想要的方式为该单词着色。例如:将单词涂tkinter成粉红色和in蓝色。但是当我输入 时Tkinter,它的颜色Tk--ter为黄色和in蓝色。
我怎样才能解决这个问题 ?谢谢 !
我正在编写一个类似记事本的项目,我需要将图像插入到 Tkinter 文本小部件中(就像 MS Word 所做的那样),但我没有找到任何帮助我解决这个问题的东西。
这是我的代码:
from PIL import Image,ImageTk
from tkinter import *
text = Text(root)
root.pack()
#Insert Image
yourImage=filedialog.askopenfilename(title = "Select your image",filetypes = [("Image Files","*.png"),("Image Files","*.jpg")])
imgFile=Image.open(yourImage)
imgToInsert=ImageTk.PhotoImage(imgFile)
text.image_create("current",image=imgToInsert)
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它只显示一个白色的图像,上面什么都没有。
我的代码有什么问题?有人可以向我解释一下吗