I am trying to update a variable every 2.5 seconds, but somehow it will not display on Tkinter.
I wrote all of the code except Tkinter related things as I have very little knowledge in that area. I manipulated code I got from a website giving an example for using Tkinter.
Here is the code:
import threading
from tkinter import *
def onclick():
pass
its1_c = 0 # first upgrade amount
its2_c = 0 # second upgrade amount
ITS1 = its1_c * 30 # amount of first upgrade owned x multiplier to money
ITS2 = its2_c * 70 # amount of second upgrade owned x multiplier to money
cashflow = 0
balance = 100
def moneygain():
global cashflow
global balance
global text
text = balance
cashflow = balance
threading.Timer(2.5, moneygain).start()
cashflow = cashflow + 10
cashflow = cashflow + ITS2
cashflow = cashflow + ITS1
balance = cashflow
print("Balance: " + str(balance))
text.insert(INSERT, balance)
root = Tk()
text = Text(root)
text.insert(INSERT, balance)
text.pack()
text.tag_add("here", "1.0", "1.4")
text.tag_add("start", "1.8", "1.13")
text.tag_config("here", background="yellow", foreground="blue")
text.tag_config("start", background="black", foreground="green")
root.mainloop()
moneygain()
When I try to display "balance" it does not update. Instead it throws out this error:
Exception in thread Thread-2:
Traceback (most recent call last):
File "D:\Python34\lib\threading.py", line 911, in _bootstrap_inner
self.run()
File "D:\Python34\lib\threading.py", line 1177, in run
self.function(*self.args, **self.kwargs)
File "D:/Python34/menugui.py", line 27, in moneygain
text.insert(INSERT, balance)
AttributeError: 'int' object has no attribute 'insert'
How can I display balance
on the Tkinter window?