get text between 2 string start with wordlist and ended with puntuation list in tkinter python -
i want take sentence between 2 strings start word list ended `/. or /? or /, or /!
the code have tried
def sumar(): start = open('f:\\skripsi\\source code\\katadata.txt', 'r' ) end = "\.|\?" test = text1.get(0.0, end) m = re.compile('(%s)(.*?)%s' % (start.read ().replace('\n','|'), end), flags = re.ignorecase) smr = m.search(test).group(2) se = text2.insert(end, smr) text1= text(root, width=50,height=30) text1.pack(side=left) text2 = text(root, width=80, height=30) text2.pack(side=left) btn5= button(root, text= "summary", command=sumar) btn5.pack(side=top)
but, when run it, it's error :
traceback (most recent call last): file "c:\python27\lib\lib-tk\tkinter.py", line 1532, in __call__ return self.func(*args) file "f:\skripsi\source code\modul-token.py", line 84, in sumar test = text1.get(0.0, end) file "c:\python27\lib\lib-tk\tkinter.py", line 3074, in return self.tk.call(self._w, 'get', index1, index2) tclerror: bad text index "\."
can me? thak you
you have redefined tk-constant end
end = "\.|\?"
. rename end
e.g. re_end
.
Comments
Post a Comment