title: How to make function return entry input value (upon button submit) in Tkinter?
body: <p>I created a function called <em>&quot;brewerInfo&quot;</em> which is supposed to ask for number of brewers, get user <em>input(entry1)</em>, and then after submitting the <em>button(button10)</em> it will trigger the callback function <em>&quot;return_value&quot;</em> which is supposed to keep the entry value inside a global variable called <code>val</code>. I want the &quot;brewerInfo&quot; function to return that val(user input/entry) so that way I can call &quot;brewerInfo&quot; function every time, I need to get a user input and store that value for later use outside of the function.</p>
  <p><strong>It seems Tkinter can only print the <code>val</code> INSIDE the return_value function but I can't seem to call the value outside of it, let alone return that value.</strong></p>
  <p>I really need to re-use this function and have it return the value so I can use that value in other functions where I call brewerInfo. Is there any way to work around this?</p>
  <p>Here's my code:</p>
  <pre><code>from tkinter import *
  from tkinter import messagebox  
  
  # setting root window:
  root = Tk()
  root.title(&quot;Creator.py GUI&quot;)
  root.config(bg=&quot;#17173c&quot;)
  root.geometry(&quot;800x400&quot;)
  
  
  #global val
  val = ''
  def brewerInfo():
      global val
      #Creates a new Tkinter window popup
      new_window = Toplevel(root)
      new_window.geometry(&quot;400x60&quot;)
      new_window.title(&quot;Brewer Info&quot;)
      new_window.config(bg=&quot;#17173c&quot;)
      #Label text 
      label2 = Label(new_window, text=&quot;Number of brewers? (1-4): &quot;)
      label2.grid(row=0, column=0)
      #return_value is a callback function that gets called after submitting the button 
      #return_value gets the entry input 
      def return_value():
          global val
          val = entry1.get()
      #prompts an entry 
      entry1 = Entry(new_window)
      entry1.grid(row=0, column=1)
      #submit the button and call return_value as callback function to get the entry value 
      button10 = Button(new_window, text=&quot;Ok&quot;, width = 10, font=&quot;System 20&quot;, bg=&quot;green&quot;, fg=&quot;black&quot;, activebackground=&quot;black&quot;, activeforeground=&quot;red&quot;, borderwidth=5, cursor=&quot;hand2&quot;, highlightthickness=0, highlightcolor=&quot;black&quot;, highlightbackground=&quot;black&quot;, command=lambda: [return_value(), new_window.destroy()])
      button10.grid(row=1, column=0)
      #return return_value()
      return val
      #print(val) #doesnt work :(
      #print(&quot;test if print works!&quot;) #works
  
      
  #brewerInfo()
  #print(val)
  print(brewerInfo()) #print the return val
  
          
  #IGNORE FOR NOW!!!!!!!!!
  #button1 calls callback function brewerInfo
  button1 = Button(root, text=&quot;Enter brewer INFO&quot;, width = 40, font=&quot;System 20&quot;, bg=&quot;red&quot;, fg=&quot;black&quot;, activebackground=&quot;black&quot;, activeforeground=&quot;red&quot;, borderwidth=5, cursor=&quot;hand2&quot;, highlightthickness=0, highlightcolor=&quot;black&quot;, highlightbackground=&quot;black&quot;, command= brewerInfo)
      
  button1.pack()
      
  # window in mainloop:
  root.mainloop()
  </code></pre>