Skip to content
Advertisement

Python Tkinter count-down GUI crashing when i start the Count-Down with a button. (app not answering)

I am making a count-down GUI with Tkinter in Python 3.10 and I’m making a slider that sets the minutes, 2 labels that display the minutes and seconds and a button to start the timer.

The problem is that it crashes when I click the start timer button, The strange thing is that it doesn’t give me any error messages it just doesn’t respond/crashes the GUI.

I’m using functions with long loops and I think the problem is with the loops.

Both the slider and Button calls functions

I’m a beginner so I know that the code isn’t so good but I’m trying my best. Please Help Me :)

Python Code:

JavaScript

Its a very difficult problem so i haven’t tried anything yet because i dont understand the problem, but as i said i think the problem is in the loops.

I was expecting it to start coundting down from the set number of minutes and when its finished just stop at 0 on both min and sec but it just crashed when i clicked start countdown.

Please help me, it would be really helpfull because this is my second GUI i have ever made without any help :)

code is fixed/question ended

Hi everyone, thanks for all the help, my code is now working by using the after function and the root.update_idletasks() function. thanks

Advertisement

Answer

As JRiggles mentioned sleep and tkinter do not go well. This is because sleep() blocks the main loop of tkinter.

The most common way to solve this issue is to use after() to manage these kind of loops.

Here is a paired down version of your code that uses a combination of after() and a refactored function.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement