#Python Program to search string in text using Tkinterfromtkinterimport*#to create a windowroot=Tk()#root window is the parent windowfram=Frame(root)#adding label to search boxLabel(fram,text='Text to find:').pack(side=LEFT)#adding of single line text boxedit=Entry(fram)#positioning of text boxedit.pack(side=LEFT,fill=BOTH,expand=1)#setting focusedit.focus_set()#adding of search buttonbutt=Button(fram,text='Find')butt.pack(side=RIGHT)fram.pack(side=TOP)#text box in root windowtext=Text(root)#text input area at index 1 in text windowtext.insert('1.0','''Type your text here''')text.pack(side=BOTTOM)#function to search string in textdeffind():#remove tag 'found' from index 1 to ENDtext.tag_remove('found','1.0',END)#returns to widget currently in focuss=edit.get()ifs:idx='1.0'while1:#searches for desired string from index 1idx=text.search(s,idx,nocase=1,stopindex=END)ifnotidx:break#last index sum of current index and#length of textlastidx='%s+%dc'%(idx,len(s))#overwrite 'Found' at idxtext.tag_add('found',idx,lastidx)idx=lastidx#mark located string as redtext.tag_config('found',foreground='red')edit.focus_set()butt.config(command=find)#mainloop function calls the endless loop of the window,#so the window will wait for any#user interaction till we close itroot.mainloop()