python - previous output remains even after passing next input -


in code, output of 1 query. if pass next query in entry box, previous output in textbox remains unchanged , not getting output of new query.

coding:-

import tkinter tk import re class sampleapp(tk.tk):     def __init__(self):         tk.tk.__init__(self)         self.l1 = tk.label(self, text="enter query")         self.l1.pack()                 self.entry = tk.entry(self)         self.button = tk.button(self, text="get", command=self.on_button)         self.button.pack()         self.entry.pack()         self.text = tk.text(self)         self.text.pack()     def on_button(self):         s1=(self.entry.get())          open("myxml.txt","rb")as f:              row = f.readlines()              i, r in enumerate(row):                 if s1 in r:                                x in range(i-3,i+4):                         s = row[x]                         m = re.sub(r'<(\w+)\b[^>]*>([^<]*)</\1>', r'\1-\2', s)                         self.text.insert(tk.end, re.sub(r'<[^<>]*>','', m))   app = sampleapp() app.mainloop() 

how can next output after passing next query? please help! in advance!

first of don't try parse xml regexp use real xml parser

i mean really stop parsing xml regexp because regexp not want. (and when happen surprised).

to come current problem have delete text widget content. 1 line @ appropriate place should enough (not tested)

import tkinter tk import re class sampleapp(tk.tk):     def __init__(self):         tk.tk.__init__(self)         self.l1 = tk.label(self, text="enter query")         self.l1.pack()                 self.entry = tk.entry(self)         self.button = tk.button(self, text="get", command=self.on_button)         self.button.pack()         self.entry.pack()         self.text = tk.text(self)         self.text.pack()     def on_button(self):         s1=(self.entry.get())          #here line added         self.text.delete(1.0, tk.end) #delete content of self.text          open("myxml.txt","rb")as f:              row = f.readlines()              i, r in enumerate(row):                 if s1 in r:                                x in range(i-3,i+4):                         s = row[x]                         m = re.sub(r'<(\w+)\b[^>]*>([^<]*)</\1>', r'\1-\2', s)                         self.text.insert(tk.end, re.sub(r'<[^<>]*>','', m))   app = sampleapp() app.mainloop() 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -