|
发表于 2019-8-13 11:15:06
|
显示全部楼层
本帖最后由 nichengang 于 2019-8-13 11:23 编辑
学习打卡,代码效果如图
- 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),'.')))
- 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()
复制代码 |
|