There are different ways. 1: declare outline global inside the function
outline = True # when the program starts
def toggle(*args): # args ignored
global outline # at the top of the function
if outline == True:
outline = False
if outline == False:
outline = True
2: use a class to hold global variables (avoid global statement)
class glo:
outline = True # when the program starts
def toggle(*args):
glo.outline = not glo.outline
3: use a module to hold global variables (especially useful is your program uses more than one file)
# in file glo.py
outline = True
# in your main program
import glo
def toggle(*args):
glo.outline = not glo.outline
3: Create a class to hold global variables and function and use a single instance
class MyApp:
def __init__(self):
self.outline = True
def toggle(self, *args):
self.outline = not self.outline
if __name__ == '__main__':
my_app = MyApp()
# ...
Button(..., command = my_app.toggle)
#...
foo.mainloop()
4: etc