Text-查找文本

 1 from tkinter import *
 2 
 3 master=Tk()
 4 text=Text(master,width=30,height=5)
 5 text.pack()
 6 text.insert(INSERT,'I love coding!')
 7 start='1.0'
 8 
 9 def getIndex(text,inde):
10     return tuple(map(int,str.split(text.index(inde),'.')))
11 
12 while True:
13     pos=text.search('o',start,stopindex=END)
14     #没有的话,返回None
15     if pos=='':
16         break
17     else:
18         print('位置是:',getIndex(text,pos))       
19         start= pos +'+1c'
20     #起始点必须往前移动
21 
22 
23 mainloop()

 

posted @ 2017-04-27 16:28  道高一尺  阅读(223)  评论(0编辑  收藏  举报