本帖最后由 nichengang 于 2019-8-13 11:29 编辑 from tkinter import *
master=Tk()
t1=Text(master,width=50,height=20)
t1.pack()
t1.insert(INSERT,'i love fishc! i love xiao jia yu!')
v=StringVar()
def getIndex(text,index):
tup=tuple(map(int,str.split(text.index(index),'.')))
# 这里有点问题:用小甲鱼的代码tuple(map(int, str.split(text.index(index), ".")))
# 不显是元组,只显示数字,所我把代码改成下面的样子。
# 求教小甲鱼老师!!!!!!
return '('+str(tup[0])+','+str(tup[1])+')'
def get_char():
v.set(e1.get())
start=1.0
while True:
pos=t1.search(v.get(),start,stopindex=END)
if not pos:
break
t2.insert(INSERT,getIndex(t1,pos))
start=pos+'+1c'
l1=Label(master,text='serch').pack()
e1=Entry(master)
e1.pack()
b4=Button(master,text='ok',command=get_char).pack()
l2=Label(master,text='position').pack()
t2=Text(master,width=30,height=10)
t2.pack()
mainloop()
|