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 :
- Python | Create a stopwatch using clock object in kivy using .kv file
- PyQt5 - Create a digital clock
- Python | Create a digital clock using Tkinter
- Python | Create a stopwatch Using Clock Object in kivy
- Create digital clock using Python-Turtle
- Draw Clock Design using Turtle in Python
- Python | time.clock() method
- wxPython - Create Radio Button using Create() function
- wxPython - Create Static Box using Create() method
- Python | Create video using multiple images using OpenCV
- How to create Label widget in PyQt5 ?
- PyQt5 – How to create circle Label ?
- PyQt5 - How to create semi transparent window ?
- PyQt5 – How to create circular image from any image ?
- PyQt5 – How to create Label with multicolor border ?
- PyQt5 – How to create dashed border of Label ?
- PyQt5 – Create multi-color border of StatusBar
- PyQt5 – Create dashed border of status bar
- PyQt5 - How to create and get the name of Push Button ?
- PyQt5 – Create translucent Push Button
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.