เมื่อเร็ว ๆ นี้ฉันได้ทำงานกับโปรแกรมแก้ไขข้อความธรรมดา GUI python รหัสเรียกใช้ฟังก์ชันนี้:
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()
อย่างไรก็ตาม ฉันไม่สามารถทำให้มันทำงานได้ รหัสควรจะเน้นคำทั้งหมดที่ควรพบ แต่ผู้ใช้จะต้องคลิกที่ปุ่ม "Find Me!!!" กี่ครั้งก็ได้ที่มีการเน้นคำให้เน้นทั้งหมด ได้ค้นหาทางอินเทอร์เน็ตเพื่อค้นหาสิ่งใดที่อาจช่วยฉันแก้ไขคุณลักษณะการค้นหานี้ แต่ฉันไม่สามารถค้นหาคำอธิบายใด ๆ เกี่ยวกับวิธีการดังกล่าวได้สำเร็จ ความช่วยเหลือในการแก้ไขคุณลักษณะการค้นหานี้จะได้รับการชื่นชมอย่างมาก
แก้ไข
นี่คือรหัสใหม่ที่ยังคงไม่สามารถแก้ปัญหาได้:
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
กับtag_add
กับเหตุการณ์เหล่านี้ทั้งหมด - person nbro   schedule 13.02.2015for targetfind in where: pastit = where + ('+%dc' % len(targetfind))
- person Pseudonym Enigma   schedule 13.02.2015