Tkinter search bar [closed]

社会主义新天地 提交于 2019-12-20 07:53:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!