
Now activate the painter by using the begin() method:. To create a half circle, we will be using the drawArc() method. In this example, we have used the DashLine as line style we can also use SolidLine to create a solid lined continuous circle as follows: tPen(QPen(Qt.green, 8, Qt.SolidLine)) Define the x and y-axis where the circle will be placed in the window and the size (height and width). We called the drawEllipse() method using the painter object we created in step 2. Draw the circle using drawEllipse(x_axis, y_axis, width, height). The value 8 is the width of the circle line. Now set the QPen for the painter and assign the color and style to the line for the circle:. The first step is to define the method where all painting work will be done the method is paintEvent():. The QPen defines the working of QPainter that is how should QPainter design or style a shape. The QBrush modules provide colors, textures, etc. The QPainter provides various functions to draw basic shapes. To draw graphics, import the following modules: from PyQt5.QtGui import QPainter, QBrush, QPen
Our window is now ready, and we can create graphics easily: Now the main steps: Create an instance of QApplication and object of Window class then execute the window. In the constructor, the parameters are initialized and in the InitWindow() method, the parameters are applied to the window using setGeometry() function. tGeometry(self.top, self.left, self.width, self.height) The second method called InitWindow, it sets the parameters we defined in our constructor, for example, the title of our application window, length, and width, etc. Inside this class, we will have two methods the first method is a constructor, which is automatically called when the object of the class is created. Now create the Window class, which provides a window for our application where we can have a menu bar, status bar, graphics, etc. To create the window, import the following modules: from PyQt5 import QtGuiįrom PyQt5.QtWidgets import QApplication, QMainWindow