|
发表于 2017-7-30 16:31:36
|
显示全部楼层
from tkinter import *
root = Tk()
text = Text(root,width=30,height=5)
text.pack()
text.tag_config("tag1",background="yellow",foreground="red")
text.insert(INSERT,"I love ")
text.insert(END,"FishC.com!","tag1")
text.insert(INSERT,"\nYou are good!")
text.mark_set("here",2.8)
text.insert("here","very ")
#text.insert(END,"o")
#将任何格式的索引号统一为元祖(行,列)的格式输出
def getIndex(text,index):
return tuple(map(int,str.split(text.index(index),".")))
start = END
while True:
pos = text.search("o",start,stopindex=1.0,backwards=True)
if not pos:
break
print("找到啦,位置是:",getIndex(text,pos))
#print(pos,type(pos))
start = pos + "-1c" #start指向下一个字符
#print(text.index(start))
mainloop()
找到啦,位置是: (2, 15)
找到啦,位置是: (2, 1)
找到啦,位置是: (1, 14)
找到啦,位置是: (1, 3)
为什么反向搜索找不到(2,14) |
|