Finn
Finn

Reputation: 33

python tkinter if no button pressed run function

I am currently working on a roulette game in tkinter. The problem is that I want the roulette automatically to run after a ceirtan time (20sec). But right now it will only run if the player inputs something inform of pressing a button and entering an amount of money. But I want the roulette to run every 20 sec even if the player didnt bet anything(so no button got pressed). But I cant seem to find out how.

pseudocode:

if no button got pressed after 20 sec: run roulette #(roll roulette without player input and without his money)

Upvotes: 0

Views: 737

Answers (1)

double_j
double_j

Reputation: 1716

Not having any code makes answering this a bit harder. I believe what you're looking for is after. This could run after a time period to check if the user has clicked to play. You should have a variable monitoring the user's clicks and reseting once the game's done.

some real code:

clicked = False

def force_play():
    if not clicked:
        play()

after(1000 * 20, force_play)

Upvotes: 1

Related Questions