-2

How could i make a clicker game where the power up button adds 1 to the score every minute. I already have a button that gives one point every time it is clicked. After you get 10 points, you can click the power up. I want it to give the player 1 point every 60 seconds.

I am currently having trouble with it working because it keeps crashing, i dont know if i need a better computer or just better code. When it runs, it will take away the tens points but do nothing after.

So i want it to Run, Main button be clicked to get points, power up button to be clikced, and then add one point every minute/60 seconds.

import turtle
import tkinter
from tkinter import *
import time
import datetime
from time import time, sleep




root = Tk()

global score
score = 0
scoreLabel = Label(root, text="Your Score:" + str(score))
scoreLabel.place(x=100, y=100)

def myClick():
    global score
    score += 1
    scoreLabel.config( text="Your Score:" + str(score))


def subClick():
    global score
    if score >= 10:
        score -= 10
        while True:
            sleep(10)
            score += 1
    scoreLabel.config( text="Your Score:" + str(score))




addButton = Button(root, text="Click Me", padx=250, pady=250, command=myClick)
addButton.pack()


powerupButton = Button(root, text="Power Up", padx=50, pady=10, command=subClick)
powerupButton.place(x=300, y=300)
powerupButton.pack()

root.mainloop()
  • 1
    What is the problem with the provided code ? – Marius ROBERT May 30 '22 at 12:21
  • I'm assuming the thing the OP is asking how to do is perform an operation in the background on a timer (which I believe we already have Q&A answering), but we shouldn't need to guess/infer/assume. – Charles Duffy May 30 '22 at 12:25
  • 1
    [What is the best way to repeatedly run a function every n seconds?](https://stackoverflow.com/questions/474528/what-is-the-best-way-to-repeatedly-execute-a-function-every-x-seconds) -- it's closed because asking for the "best" anything without objective criteria for selecting a specific answer is off-topic here, but it got plenty of answers before that happened. – Charles Duffy May 30 '22 at 12:27
  • I am Trying to make a clikcer game and want to make a power up that adds to the score every minute, and it keeps crashing. – It's Hand-amazing May 30 '22 at 12:30
  • Change this addButton = Button(root, text="Click Me", padx=50, pady=50, command=myClick) if you used 250, you splashed whole screen. Btw, resizing window to see score – toyota Supra May 30 '22 at 13:08

0 Answers0