0

So, my plan is to create one of those games where a sequence is shown on the screen and you have to click the correct buttons, following the sequence. I'm going to use Tkinter for this project. Here's some explanation: When any buttons is clicked, a function will be executed with a parameter that will tell which button has been clicked, and then the function will check whether it's the correct button or not.

THE PROBLEM: if the user clicked the right button, this function will call a second function to show the next buttons of the sequence. The thing is that it should take some time to display this, and meanwhile the tkinter button remains 'clicked'. I don't want it to happen, also because you cannot execute other tasks, such as leaving the game or restarting the round, while this is happening.

Here I have a simple example to show you the problem, if you couldn't see it yet:

import tkinter as tk
from time import sleep

def func():
    print('hi')
    func2()

def func2():
    print('hi2')
    for num in range(3, 11):
        sleep(1)
        print('hi' + str(num)) 

wn = tk.Tk()
b1 = tk.Button(wn, command=func)
b1.pack()
wn.mainloop()

In this case, the code should print 'hi' + the numbers from 1 to 10 when the button is pressed. However, the things I've said previously happen.

How can I make this example above work correctly and also my project?

Gaper
  • 1
  • 1

1 Answers1

0

You can either use threads or you can define func3 which runs func1 and func2.

Landon
  • 119
  • 11