Mar-25-2019, 05:24 AM
(This post was last modified: Mar-25-2019, 05:24 AM by poopcupine.)
Hi all,
I am trying to highlight similar documents using tkinter GUI.
I have a dictionary that reads from 2 documents and put similar words into the one dictionary, key being the word and value being the occurence of the word.
My tkinter gui will highlight using the text widget search to search for the key in the dictionary, if found in any of the document, it will highlight the word. However, it is not highlighting some of the words and I can't figure out why..
Below is my function for the highighting, compare is my dictionary
{'lol.csv': 1, 'a': 1, 'c': 1, 'f': 1, 'ahahhahahha': 1, 'haha': 1, 'dog': 1, 'aaaa': 1, '=': 1}
Below is an image of the output I get:
https://www.dropbox.com/s/r3wcnu8z0ko59a...t.PNG?dl=0
Any help is greatly appreciated
I am trying to highlight similar documents using tkinter GUI.
I have a dictionary that reads from 2 documents and put similar words into the one dictionary, key being the word and value being the occurence of the word.
My tkinter gui will highlight using the text widget search to search for the key in the dictionary, if found in any of the document, it will highlight the word. However, it is not highlighting some of the words and I can't figure out why..
Below is my function for the highighting, compare is my dictionary
from Tkinter import * #Highlight function to highlight similar words def highlight(line,text,linenumber,compare): #Create text field for doc1 and co2 print compare text.configure(state='normal') text.insert(INSERT, line) text.pack() text.tag_config('same', background='yellow') #Iterate through thte dictionaries to look for key and highlight key based of the value of the key. for key, value in compare.iteritems(): pos = '1.0' # <-- position is resetted to 1 in each iteration for i in range(value): idx = text.search(key, pos, END) #Uses tkinter text widget search to search for dictionary key in .py file1 and .py file2 if not idx: break print "key: " + str(len(key)) pos = '{}+{}c'.format(idx, len(key)) text.tag_add('same', idx, pos)when i print my dictionary:
{'lol.csv': 1, 'a': 1, 'c': 1, 'f': 1, 'ahahhahahha': 1, 'haha': 1, 'dog': 1, 'aaaa': 1, '=': 1}
Below is an image of the output I get:
https://www.dropbox.com/s/r3wcnu8z0ko59a...t.PNG?dl=0
Any help is greatly appreciated