I have a program for a school project that is a game based around clicking a target that randomly spawns. Currently, when I am clicking the target nothing is happening and not directing to the hitcounter function. My laptop is a bit slow but whenever I try to click on the button there is no registration graphically of a click either.
I tried redundantly the use of lambda which did not solve the issue, but I saw two people request for my function that I call upon after button click, so I have provided it. If there are any further queries please ask, I will not be losing this account.
...
def hitcounter(*args):
print(" wdwd ")
hitcounter += 1
canvas.delete("counter1_")
counter1_ = canvas.create_text(screenwidth-50,screenheight/4,fill="Blue",font="Times 20",text="HiTS:"+'\n '+str(hitcounter), tag='counter1')
#as requested, I hope this helps thanks!
spawntarget()
def spawntarget():
print("spawntarget")
x_target = random.randint(75,screenwidth-75-50)
y_target = random.randint(75,screenheight-75-100)
global clicktarget
clicktarget=Button(root ,text='ENEMY', width=10, height=10, command = hitcounter)
clicktarget.configure(fg='red', bg='gold')
print("spawntarget2")
while True:
clicktarget.place(x=x_target,y=y_target)
canvas.update()
time.sleep(3)
x_target = random.randint(75,screenwidth-75-50)
y_target = random.randint(75,screenheight-75-100)
root.mainloop()
#I want my button to be clicked and
#call upon the hitcounter function,
#but currently it does not and there
#is no error message. Thanks for looking at my problem.