Jan M.
Jan M.

Reputation: 501

Update a Tkinter Text widget real time?

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.

Upvotes: 0

Views: 1581

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

I don't understand what you mean by "work in real time", but I definitely see a bug in your code. The command option takes a reference to a command but you're giving it a string. Change the button definition to this:

self.v = Button(master, text="Add text", command=Write)

Upvotes: 2

Related Questions