Digital clock using PyQt5 in Python
In this post, we'll see at how to make a digital clock using PyQt5, which essentially displays the time in 24-hour format. We will be focussing on making a GUI that will show the current time in HH:MM:SS format by opening a window.
The following must be done in order to make a digital clock :
Walking through the code :
Firstly, we will import all the libraries required by our program, that include QtWidgets, QtGui, QtCore and sys.
Next, we will create a new class to initialize our GUI window and start setting the geometry, adding fonts, creating labels, setting alignment and displaying widgets.
Next, we will create the layout of our window. Then, we will create a timer clock timer, add a functionality to it for getting updated after every second and call the function linked to it.
Next, we will create a function that contains the present time to be displayed, the time label to be updated and the text display field.
Finally, we will create the application and the instance of the window. Then, the instance created will be displayed and the program will be called to execute and start the application.
Complete code :
The output of the above mentioned code is attached below in the for of screenshot,
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week