我尝试在tkinter Tetx小部件中搜索Python关键字(print,for,if,while ....),但是我的代码找到了关键字和单词,其中包含关键字,我必须删除这些单词。感谢帮助。 我的代码:
import tkinter as Tk
def search(word):
try:
pos = t.search(word,"insert", stopindex="end")
col, line = pos.split(".")
except ValueError:
print("all")
else:
print(pos)
t.mark_set("insert","%i.%i"%(int(col),int(int(line)+len(word))))
search(word)
main=Tk.Tk()
t = Tk.Text(main)
t.pack()
t.insert("insert","word in tkinter")
t.mark_set("insert","1.0")
search("in")
main.mainloop()