I am writing a small game in Python 3.7. It took time to score. Those. every second since the launch of the program, one point should be added to the score. There is this code that needs to be improved to a working state or to offer alternative ways to solve the problem.

score = 0 def label2(): global SCORElabel SCORElabel = c.create_text(350, 10, width=300, text="Score: " + str(score), fill='#fff', anchor=NW) def scoremeter(): global score game_time = time.clock() if game_time//1==0: score+=1 c.delete(SCORElabel) label2() scoremeter() else: scoremeter() 

    1 answer 1

    tkinter has a built-in function tkinter.Tk.after("second", func) which allows you to repeat the function once a certain number of seconds, the example below

     import tkinter as tk class Main(tk.Tk): score = 0 def __init__(self): super(Main, self).__init__() self.label = tk.Label(self, text="Количество очков 0") self.label.pack() self.score_plus() def score_plus(self): self.score += 5 self.label["text"] = "Количество очков {}".format(self.score) self.after(1000, self.score_plus) if __name__ == "__main__": Main().mainloop()