Javatpoint Logo
Javatpoint Logo

Countdown Timer using PyQt5 in Python

This article will demonstrate how to build a countdown timer application using PyQt5. When using a timer, which is a particular sort of clock used to measure certain time intervals, we must count down from the supplied time until it reaches zero.

Steps for implementing a GUI :

  1. Make a push button that opens a pop-up window for time display and configure its shape.
  2. Label the time and the status of completion.
  3. Set the label's size, font, and text alignment to centre.
  4. Make three push buttons: one for the timer's start, one for its pause, and one for its reset.
  5. Set each button's geometry.

Implementation procedure for the back end :

  1. Create a count variable and a flag to indicate whether the counter is running or not.
  2. Give each button a function.
  3. Get the value of the second using the input dialogue box within the get second button action, then set the flag to false.
  4. Make the flag true within the start action, but if the count is zero, make the if false.
  5. Inside the pause action, set the flag to false.
  6. Set the count value to zero, the flag to false, and the label's text as part of the reset process.
  7. Create an object called a timer that calls its method every 100 milliseconds.
  8. Check for the flag inside the timer action, then reduce the value of the count and set the label's content.

Walking through the code :

First, import all the required libraries into the program.

Next, create a class to initialise the window and set its properties.

Then, create a method to introduce all components, add buttons and add labels to display text.

Then, create the functions to be called when different buttons are clicked and what should the action done after that.

Lastly, create an instance of the window to be displayed and execute the application.

Complete code for the project :

Output:

The output of the above mentioned code is attached below in the form of a screenshot.

Countdown Timer using PyQt5 in Python





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA