title: How do I return variables from a function in Tkinter?
body: <p>I have been trying to make a simple dice rolling GUI where you press a button and a dice rolls and gives you the output in a label. When I run my code I get the error that "diceOutput" is not defined. Here is my code:</p>
  
  <pre><code>from tkinter import *
  import random
  
  window = Tk()
  
  window.title("Dice")
  
  def rollDice():
      diceOutput = str(random.randint(1,6))
      return diceOutput
  
  roll = Button(window, text="Roll", command=rollDice)
  output = Label(window, textvariable=diceOutput)
  
  window.mainloop()
  </code></pre>