from Tkinter import *
class Output:
def __init__(self,master):
self.u=Text(master,width=40)
self.u.grid(row=0,column=0)
self.v=Button(master,text="Add text",command="Write")
self.v.grid(row=1,column=0)
def Write(self):
self.u.insert(1.0,"Meh")
root=Tk()
output=Output(root)
root.mainloop()
How do I make the button work in real time? If possible, I’d like to have an explanation why this won’t work.
I don’t understand what you mean by “work in real time”, but I definitely see a bug in your code. The
commandoption takes a reference to a command but you’re giving it a string. Change the button definition to this: