baru-baru ini saya sedang mengerjakan editor teks biasa GUI python. Kode memanggil fungsi ini:
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()
Namun, saya tidak bisa menjalankannya. Kode tersebut seharusnya menyorot semua kata yang seharusnya ditemukan, namun pengguna harus mengklik tombol "Temukan Saya!!!" sebanyak kata yang perlu disorot untuk menyorot semuanya. telah mencari di internet untuk mencari apa pun yang mungkin dapat membantu saya memperbaiki fitur pencarian ini, tetapi saya belum berhasil menemukan penjelasan apa pun tentang bagaimana saya dapat melakukannya. Bantuan apa pun dalam memperbaiki fitur pencarian ini akan sangat dihargai.
Sunting
Ini adalah kode baru yang masih belum menyelesaikan masalah:
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()
tag
dengantag_add
Anda ke semua kemunculan ini. - person nbro   schedule 13.02.2015for targetfind in where: pastit = where + ('+%dc' % len(targetfind))
- person Pseudonym Enigma   schedule 13.02.2015