recently I have been working on a GUI python plain text editor. The code calls this function:
def Find(event=None):
def find_button_pressed():
targetfind = e1.get()
print targetfind
if targetfind:
where = textPad.search(targetfind, INSERT, END)
if where:
print where
pastit = where + ('+%dc' % len(targetfind))
#self.text.tag_remove(SEL, '1.0', END)
textPad.tag_add(SEL, where, pastit)
for targetfind in where:
textPad.mark_set(INSERT, pastit)
textPad.see(INSERT)
textPad.focus()
win = Toplevel()
Label(win, text="Find:").pack()
e1 = Entry(win)
e1.pack()
Button(win, text="Find Me!!!!", command=find_button_pressed).pack()
textPad.focus()
However, I cannot get it to work. The code is supposed to highlight all of the words that are supposed to be found, however, the user must clicks on the button "Find Me!!!" as many times as there are words to be highlighted in order to highlight all of them. have searched the internet looking for anything that might help me fix this find feature, but I have not succeeded in finding any explanations as to how I might do so. Any help in fixing this find feature would be very much appreciated.
EDIT
This is the new code that still does not solve the problem:
def Find(event=None):
def find_button_pressed():
start = "1.0"
end = "end"
start = textPad.index(start)
end = textPad.index(end)
count= Tkinter.IntVar()
count=count
textPad.mark_set("matchStart", start)
textPad.mark_set("matchEnd", start)
textPad.mark_set("searchLimit", end)
targetfind = e1.get()
print targetfind
if targetfind:
while True:
where = textPad.search(targetfind, "matchEnd", "searchLimit",
count=count)
if where == "": break
elif where:
print where
pastit = where + ('+%dc' % len(targetfind))
textPad.tag_remove(SEL, '1.0', END)
textPad.mark_set("matchStart", where)
textPad.mark_set("matchEnd", "%s+%sc" % (where, count.get()))
textPad.tag_add(SEL, where, pastit)
textPad.see(INSERT)
textPad.focus()
win = Toplevel()
Label(win, text="Find:").pack()
e1 = Entry(win)
e1.pack()
Button(win, text="Find Me!!!!", command=find_button_pressed).pack()
textPad.focus()