I need some help! I'm learning tkinter and I decided to make a game. I made a button and one label, so when you click the button, it will move randomly on screen and label will count your clicks. Now, I need a timer, but I don't know how to make it. The game should be like this: https://scratch.mit.edu/projects/2245518/
Here's my code:
from tkinter import *
from random import randint
import
root = Tk()
root.geometry('600x470')
root.title('Catch The Button - Game')
clicks = 0
def change():
global clicks
clicks += 1
clicksLabel['text'] = 'Clicks: ' + str(clicks) + 180 * ' '
rand = randint(1,5)
if rand == 1:
button.pack(side = LEFT, padx = randint(1, 220), pady = randint(1, 220))
elif rand == 2:
button.pack(side = RIGHT, padx = randint(1, 220), pady = randint(1, 220))
elif rand == 3:
button.pack(side = TOP, padx = randint(1, 220), pady = randint(1, 220))
else:
button.pack(side = BOTTOM, padx = randint(1, 220), pady = randint(1, 220))
clicksLabel = Label(root, text = 'Clicks: 0' + 180 * ' ')
clicksLabel.pack()
button = Button(root, text = 'Catch me :P', command = change)
button.pack(side = RIGHT, padx = randint(1, 220), pady = randint(1, 220))
root.mainloop()