![]() |
tkinter search box - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: tkinter search box (/thread-25627.html) |
tkinter search box - DT2000 - Apr-06-2020 I am attempting to find the correct way to put a search entry in a piece of code I have written. The entry widget would hold the input as a StringVar() that would be searched in a text widget and then highlight the word when found. I have a reasonable idea of what I have to do and part of how I need to do it but I have not been able to get it to come together in a working form yet. I have done some looking online for information and managed to find limited information and a couple of examples but I have not been able to make my search code work yet. The text widget is Code_Snippet: Code_Snippet = Text(root, bg = '#FFFFDF', fg='#000000', bd=0, width=117, height=27, relief=SUNKEN, cursor='hand2') Code_Snippet.place(x=19,y=58)The Entry widget is search_entry: search_entry = Entry(root,bd = 2, textvariable = Search, width = '25', bg='#FAFAFA', cursor='hand2') search_entry.place(x=770,y=32)Search routine: Search = StringVar() pos = Code_Snippet.search(Code_Snippet, "1.0", stopindex="end", count=Search) Code_Snippet.tag_configure('search', background="light blue") Code_Snippet.tag_add('search', pos, "%s + %sc" (pos, Search.get()I am having issues with this and could use some advice on how to correct the code so it will actually find the word and highlight it once it is found. RE: tkinter search box - joe_momma - Apr-06-2020 I made a simple dictionary found here that searches for a word and outputs the definition in blue, examples in purple and lemmas in red. You'll need the nltk(natural language tool kit) module to run it. Looks like you're missing a step insert into the text, best of luck RE: tkinter search box - joe_momma - Apr-06-2020 Quote:Hi Joe_momma, I have checked the code that you posted and I have adapted it to my needs however it is not yet working. The problem I am facing is trying to read the data that is loaded into the Text widget. When I ran my code with the adapted portion of your code I get the following error:Please keep this to your original post- in your first post you declare code_snippet as a text widget Quote:Code_Snippet = Text(root, bg = '#FFFFDF', fg='#000000', bd=0, width=117, height=27, relief=SUNKEN, cursor='hand2')in your error defs= code_snippet() code_snippet is a widget not a function that's why your getting an error, post your code or at least a workable section- when i said you are missing the step insert you should have a line that looks like this Code_Snippet.insert('end','some-text','search') #(location, text or entry, tag) RE: tkinter search box - DT2000 - Apr-08-2020 After a lot of additional reading and various trials I now have it working as I needed it, thank you for the help. |