I am new to coding and trying to figure this out and I cannot, and I can't seem to find any videos on youtube that shows this either.
Essentially what i want to do is have a loop running, and be able to click a button and it change a variable in the loop. For instance:
from tkinter import *
import time
root = Tk()
x = 0
def changeVariable():
x = x + 5
button1 = Button(root, text="add 5", command=changeVariable)
button1.pack()
while True:
root.mainloop()
while x > 0:
print("X is greater than 0")
x = x - 1
time.sleep(1)
else:
print("Please click the button")
time.sleep(1)
I have tried all sorts of things and i cannot get the button to change the value of X in my while loop. Can someone please explain how to do this or link a video/guide that does a good job explaining this to a novice?
Thanks
mainloopin a loop. It should be called exactly once.