I get the following error in python 2.7, under the method updateText
when I try to call self.editArea.insert()
.
AttributeError: 'App2' object has no attribute 'editArea'
My code is:
import Tkinter as tk
import threading
class App2(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.start()
def callback(self):
self.root.quit()
def run(self):
self.root = tk.Tk()
self.root.protocol("WM_DELETE_WINDOW", self.callback)
self.root.geometry("200x100")
self.COMframe = tk.Frame(self.root, width=200, height=100, bg = '#ffffff', borderwidth=1, relief="sunken")
self.scrollbar = tk.Scrollbar(self.COMframe)
self.editArea = tk.Text(self.COMframe, width=200, height=100, yscrollcommand=self.scrollbar.set, borderwidth=0, highlightthickness=0)
self.scrollbar.config(command=self.editArea.yview)
self.scrollbar.pack(side="right", fill="y")
self.editArea.pack(side="left", fill="both", expand=True)
self.COMframe.grid(row=1, column=1)
#self.editArea.config(state=tk.NORMAL)
#self.editArea.delete(1.0, tk.END)
self.editArea.insert(tk.END, "hello world\n this is my text")
#self.editArea.config(state=tk.DISABLED)
self.root.mainloop()
def updateText(self, string):
#self.editArea.config(state=tk.NORMAL)
#self.editArea.delete(1.0, tk.END)
self.editArea.insert(tk.END, string)
#self.editArea.config(state=tk.DISABLED)
app2 = App2()
r = 0
while True:
s = "r={}".format(r)
app2.updateText(s)
r = r+1
print s
I don't understand why python won't see editArea
. Does it have to do with the fact that it is declared in run(self)
?