title: How to make a timer inside a def funtion/thread
body: <p>I have been trying to a reaction test the problem is that when i define a variable for time inside a def funtion it later says that that varieble is not defined. I would realy like to know how you define a varieble for time.time() inside a def funtion. The desired outcome is that it should print the time between start and end times.</p>
  <pre><code>import turtle
  import time
  wn = turtle.Screen()
  wn.title(&quot;Temp&quot;)
  wn.setup(width=600,  height=600 )
  wn.tracer(0)
  wn.bgcolor(&quot;blue&quot;)
  
  def temp(x, y):
      start = time.time()
      wn.onscreenclick(temp2)
  wn.onscreenclick(temp)
  def temp2(x, y):
      end = time.time()
      total = end - start
      print (total)
  wn.mainloop()
  </code></pre>
  <p>here is the specific error code:</p>
  <pre><code>Exception in Tkinter callback
  Traceback (most recent call last):
    File &quot;C:\Users\erigo\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py&quot;, line 1883, in __call__
      return self.func(*args)
    File &quot;C:\Users\erigo\AppData\Local\Programs\Python\Python38\lib\turtle.py&quot;, line 675, in eventfun
      fun(x, y)
    File &quot;C:/Users/erigo/PycharmProjects/Reactiontest/Reaction_test.py&quot;, line 38, in click
      total = end - start
  NameError: name 'start' is not defined
  </code></pre>