I'm writing a VERY simple incremental game in Python (final product will almost certainly be less than 5000 lines), and I've come to a problem. So far, all the currency is added solely by clicking, but the next upgrade I'm adding is going to add a certain number to the main currency every second. It should be noted that I'm using Tkinter with Python for this, so my variables are all IntVar()'s. If I have the current currency set to 500, and the cps (currency per second) to 1, how do I add 1 to my currency = IntVar() every second?
currency = IntVar()
currency.set(500)
cps = IntVar()
cps.set(1)
I'm also assuming (possibly incorrectly) that it'll be a while loop and that I'll probably have import time and time.sleep(1) in there somewhere. Any help is much appreciated!
time.sleep()is not reliable. It may sleep for longer than you ask, or wake up early. On consumer grade hardware, you should be prepared to deal with (at least) hundreds of milliseconds of error. This will become more pronounced the more CPU-intensive programs you have running.aftermethod of Tk widgets.after, for some reason...