title: How to change Label according to user input in tkinter app?
body: <p>I am creating a planning app and I want it to be personalized by having a title that says [Name]'s Planner. The user can enter their name into a text entry widget, press <kbd>Submit</kbd>, and then it will be displayed in the label. My application also has multiple pages, so the text entry will be on the start page and the label will be on the home page.</p>
  <p>I have named the text entry widget <code>nameentry</code> and have created a function that takes the data from <code>nameentry</code> and displays it in the label <code>name_label</code>, however, I am getting an error message when I try to call the function by clicking the <kbd>Submit</kbd> button which says <code>NameError: name 'nameentry' is not defined</code>.</p>
  <p>I am confused as I believe I have already defined <code>nameentry</code> by saying it equals the text entry widget.</p>
  <pre><code>import calendar
  import tkinter as tk
  from tkinter import ttk
  from tkcalendar import *
  from datetime import datetime
  
  
  #calendar and display in label
  
  #window = Tk()
  
  #window.title(&quot;StudyFriendO&quot;)
  
  LARGE_FONT= (&quot;Verdana&quot;, 24)
  
  class StudyFriendO(tk.Tk):
  
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)
  
          self.title(&quot;StudyFriendO&quot;) #naming window title
          self.geometry('850x830') #size of window
  
          container = tk.Frame(self)
          container.pack(side=&quot;top&quot;, fill=&quot;both&quot;, expand = True)
          container.grid_rowconfigure(0, weight=1)
          container.grid_columnconfigure(0, weight=1)
  
          self.frames = {}
  
          for F in (StartPage, HomePage, ToDoPage, TimetablePage): #list of multiple frames of program
              frame = F(container, self)
              self.frames[F] = frame
              frame.grid(row=0, column=0, sticky=&quot;nsew&quot;)
  
          self.show_frame(StartPage)
  
      def show_frame(self, cont):
  
          frame = self.frames[cont]
          frame.tkraise()
  
      def set_date(self, cont):
          #frame: StartPage = self.frames[cont]
          #frame.date_label.config(text=&quot;Today's date is &quot; + datetime.today().strftime(&quot;%B %d, %Y&quot;)) #function to get date from
          frame2: HomePage = self.frames[HomePage]
          frame2.date_label.config(text= datetime.today().strftime(&quot;%B %d, %Y&quot;)) #function to get date from
  
      def getname(self, cont): #FUNCTION WHICH GRABS NAME FROM TEXT ENTRY
          frame2: HomePage = self.frames[HomePage]
          frame2.name_label.configure(text=nameentry.get() + &quot;'s Planner &quot;)
  
  
  class StartPage(tk.Frame): #creating start page
      def __init__(self, parent, controller):
          tk.Frame.__init__(self,parent)
  
          label = tk.Label(self, text=&quot;StudyFriendO&quot;, font = LARGE_FONT, bg=&quot;#f2fcff&quot;)
          label.pack(fill=&quot;x&quot;)
  
          #place(x=315,y=100)
  
          photo1 = tk.PhotoImage(file='apple.png') #photo1 is a variable
          #label (window, image=photo1, bg=&quot;black&quot;) .grid(row=0, column=0, sticky=E)
          panel = tk.Label(self, image = photo1)
          panel.image = photo1
          panel.pack(fill=&quot;x&quot;)
  
          #place(x=270,y=150)
  
          label2 = tk.Label(self, text=&quot;Enter today's date and your first name below:&quot;, bg=&quot;#f2fcff&quot;)
          label2.pack(fill=&quot;x&quot;, ipady=20)
  
          #place(x=305, y=400)
  
          cal = Calendar(self, background=&quot;#e0f6fc&quot;, disabledbackground=&quot;white&quot;, bordercolor=&quot;light blue&quot;, headersbackground=&quot;light blue&quot;, normalbackground=&quot;#e0f6fc&quot;, foreground=&quot;black&quot;, normalforeground='black', headersforeground='white', selectmode=&quot;day&quot;, year=2021, month=8, day=9)
          cal.place(relx=0.5, rely=0.5, anchor='center')
          #(x=300,y=430) #calendar
  
          #TEXT ENTRY WHERE PERSON INPUTS NAME
          nameentry = tk.Entry(self, width=20, bg=&quot;white&quot;) #text input for users name
          nameentry.place(relx=0.5, rely=0.68, anchor='center')
          #(x=365, y=635)
  
          caldate = ttk.Button(self, text=&quot;Submit&quot;,
                              command=lambda: controller.set_date(StartPage)) #button to get current date
          caldate.place(relx=0.5, rely=0.63, anchor='center')
  
          button1 = ttk.Button(self, text=&quot;Enter&quot;,
                              command=lambda: controller.show_frame(HomePage)) #button to navigate page
          button1.place(relx=0.5, rely=0.73, anchor='center')
          #(x=387,y=660)
  
          #BUTTON WHICH CALLS FUNCTION WHICH GRABS NAME (CURRENTLY LOCATED IN WEIRD LOCATION)
          namebutton = ttk.Button(self, text=&quot;Submit&quot;, command=lambda: controller.getname(StartPage))
          namebutton.place(relx=0.5, y=60)
          #self.date_label = tk.Label(self, text=&quot;&quot;) #label to display date
          #self.date_label.pack(pady=20)
  
          self.configure(bg='#f2fcff')
  
  
  class HomePage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          #label = tk.Label(self, text=&quot;Home&quot;, font = LARGE_FONT)
          #label.pack(pady=10,padx=10)
  
          #width of x
          frame = tk.Frame(self, bg=&quot;#c0e3ed&quot;, height=110)
          frame.pack(fill=&quot;x&quot;)
          #LABEL WHICH DISPLAYS NAME FROM TEXT ENTRY
          #tk.Label(self, text =&quot;Name's Planner&quot;, fg=&quot;white&quot;, bg=&quot;#c0e3ed&quot;, font = LARGE_FONT).place(relx=0.5, y=50, anchor='center')
          self.name_label = tk.Label(self, text=&quot;&quot;, font=(&quot;Arial Bold&quot;, 50))
          self.name_label.place(x=0, y=0)
  
          self.date_label = tk.Label(self, text=&quot;&quot;, bg=&quot;#c0e3ed&quot;)
          # keep placing the label at top right corner
          self.date_label.place(relx=1, y=0, anchor='ne')
          #pack(side='top', anchor='ne')
  
          #height of Y
          tk.Label(self, text=&quot;&quot;, fg=&quot;white&quot;, bg=&quot;#99cbd8&quot;).pack(side=&quot;left&quot;, fill=&quot;y&quot;, ipadx=73)
  
          button1 = tk.Button(self, height=2, width=10, bg=&quot;#e0f6fc&quot;, text=&quot;Home&quot;, command=lambda: controller.show_frame(HomePage)) #button to navigate page
          button1.place(x=35, y=145)
  
          button1 = tk.Button(self, height=2, width=10, bg=&quot;#e0f6fc&quot;, text=&quot;To Do&quot;, command=lambda: controller.show_frame(ToDoPage)) #button to navigate page
          button1.place(x=35, y=225)
          #(relx=0.2, rely=0.4, anchor='center')
  
          button1 = tk.Button(self, height=2, width=10, bg=&quot;#e0f6fc&quot;, text=&quot;Timetable&quot;, command=lambda: controller.show_frame(TimetablePage)) #button to navigate page
          button1.place(x=35, y=305)
  
          photo2 = tk.PhotoImage(file='apple.png') #photo1 is a variable
          #label (window, image=photo1, bg=&quot;black&quot;) .grid(row=0, column=0, sticky=E)
          panel = tk.Label(self, image = photo2)
          panel.image = photo2
          panel.place(x=35, y=400)
  
          self.configure(bg='#f7f6f6')
  
  
  class ToDoPage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text=&quot;To Do&quot;, font = LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          button1 = ttk.Button(self, text=&quot;Home&quot;,
                               command=lambda: controller.show_frame(HomePage)) #button to navigate page
          button1.pack()
  
          button1 = ttk.Button(self, text=&quot;Timetable&quot;,
                               command=lambda: controller.show_frame(TimetablePage)) #button to navigate page
          button1.pack()
  
          button1 = ttk.Button(self, text=&quot;To Do&quot;,
                               command=lambda: controller.show_frame(ToDoPage)) #button to navigate page
          button1.pack()
  
  
  class TimetablePage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          label = tk.Label(self, text=&quot;Timetable&quot;, font = LARGE_FONT)
          label.pack(pady=10,padx=10)
  
          button1 = ttk.Button(self, text=&quot;Home&quot;,
                               command=lambda: controller.show_frame(HomePage)) #button to navigate page
          button1.pack()
  
          button1 = ttk.Button(self, text=&quot;Timetable&quot;,
                               command=lambda: controller.show_frame(TimetablePage)) #button to navigate page
          button1.pack()
  
          button1 = ttk.Button(self, text=&quot;To Do&quot;,
                               command=lambda: controller.show_frame(ToDoPage)) #button to navigate page
          button1.pack()
  
  
  app = StudyFriendO()
  app.mainloop()
  </code></pre>