import sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QPainter, QPen class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Lines') self.show() def paintEvent(self, e): qp = QPainter(self) qp.setPen(QPen(Qt.black, 5, Qt.SolidLine)) qp.drawLine(20, 40, 250, 40) qp.drawLine(20, 80, 250, 80) qp.drawLine(20, 120, 250, 120) qp.drawLine(20, 160, 250, 160) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QPainter, QBrush, QPen from PyQt5.QtCore import Qt class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Rectangle') self.show() def paintEvent(self, e): qp = QPainter(self) qp.setBrush(QBrush(Qt.red)) qp.setPen(QPen(Qt.black, 5, Qt.SolidLine)) qp.drawRect(100, 100, 150, 150) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())Both examples are PyQt5 packages.