问题
Good day house. Please I want help on how to place a search box on my tkinter application toplevel so that my users can search for anything on each page. Here is my sample code (edited).
import tkinter
frame = tkinter.Tk()
e1 = tkinter.Entry(frame)
e1.grid(column=0, row=0)
def text():
text = l.get()
text = e.get()
def t():
a = e1.get
start = "1.0"
while True:
countVar = tkinter.StringVar()
pos = text.search(a, start, stopindex="end", count=countVar)
if not pos:
break
text.tag_config("search", background="yellow")
text.tag_add("search", pos, "%s + %sc" (pos, countVar.get()))
start = pos + "+1c"
ok = tkinter.Button(frame, text="ok", command=t).grid(column=1, row=0)
l = tkinter.Label(frame, text="Hello everybody")
l.grid(column=0, row=2)
l = tkinter.Label(frame, text="Jesus loves you")
l.grid(column=0, row=3)
l = tkinter.Label(frame, text="what is happening")
l.grid(column=0, row=4)
e = tkinter.Entry(frame)
e.grid(column=0, row=5)
e = tkinter.Entry(frame)
e.grid(column=0, row=6)
frame.mainloop()
来源:https://stackoverflow.com/questions/59325331/tkinter-search-bar