Prerequisite: Introduction to pyqt-5
A clock or watch is called “analog” when it has moving hands and (usually) hours marked from number 1 to 12 to show you the time. Some have Roman Numerals (I, II, III, etc) instead, or no numbers at all! In other words: not a digital clock.
PyQt5 is a cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library. A GUI application consists of Front-end and Back-end.
- Create a Clock class which inherits the QMainWindow class.
- Inside the Clock class creating a timer object which updates the whole code after each second.
- Create three polygon objects for each hand of the clock .
- Create a paint event method.
- Inside the paint event method get the current time and the minimum of windows width or height .
- Create a painter object and a method to draw the hands.
- Inside the method for drawing hands(pointer) take arguments like color, rotation and and polygon object.
- Rotate the painter object and draw the pointer.
- Inside the paint event method, according to the current time set the rotation value and call the draw pointer method.
- Draw the background image of the clock i.e lines for each hour.
Below is the implementation :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course