title: Tkinter button add line to message
body: <p>I'm trying to make a simple gui application in python using tkinter. There is a message field, an entry, and a button. I am trying to write a command for the button which sends the text in the entry to the message field then clears the entry. Here is my code:</p>
  
  <pre><code>from tkinter import *
  from tkinter.ttk import *
  
  class window(Frame):
  
      def __init__(self, parent):
          messageStr="Hello and welcome to my incredible chat program its so awesome"
  
          Frame.__init__(self, parent)
  
          self.parent = parent
  
          self.parent.title("Hello World")
          self.style = Style()
          self.style.theme_use("default")
  
          self.pack(fill=BOTH, expand="yes")
  
          lfone = Frame(self)
          lfone.pack(fill=BOTH, expand="yes")
  
  
          myentry = Entry(self).pack(side=LEFT, fill=BOTH, expand="yes", padx=5)
  
          messager = Message(lfone, text=messageStr, anchor=S+W, justify=LEFT).pack(fill=BOTH, expand="yes", padx=5, pady=5)
  
          sendbutton = Button(self, text="Send", command=self.sendbuttoncommand).pack(side=RIGHT)
  
      def sendbuttoncommand(*args):
          messager.text = messager.text + myentry.get()
          myentry.delete(first, last=None)
  
  
  def main():
  
      root = Tk()
      root.geometry("300x200+300+300")
      app=window(root)
      root.mainloop()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>I've tried a few variations of sendbuttoncommand, including nesting it within def <strong>init</strong>, and changing messager and my entry to self.messager/myentry but have had no success. As it stands, when I try to run it  I get a nameerror on messager. How can I affect variables outside of the scope of the method? I was hoping to avoid using global variables in this instance.</p>