1

I have put a variable that gets updated inside a small method but when I go to use it later on in my code in different methods it shows up as undefined. Do I somehow have to make this variable global? If yes, how would I do that? Here's the code:

def getval():
    threading.Timer(0.5, getval).start()
    time_interval = slide.get()
    print(time_interval)


getval()

This method essentially takes the value (integer) from the scale widget (a slider) in python and updates it every half a second. I then later use the time_interval variable to control different timings.

This is the error I am getting:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Mihkel\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:/Users/Mihkel/Documents/PyCharm/main.py", line 40, in optionselected
    rb()
  File "C:/Users/Mihkel/Documents/PyCharm/main.py", line 86, in rb
    re()
  File "C:/Users/Mihkel/Documents/PyCharm/main.py", line 75, in re
    root.after(time_interval, blu)
NameError: name 'time_interval' is not defined
martineau
  • 119,623
  • 25
  • 170
  • 301
Mihkel
  • 689
  • 7
  • 34

0 Answers0