import sys from PyQt4.QtGui import * app = QApplication(sys.argv) window = QWidget() window.setGeometry(100, 100, 200, 200) painter = QPainter(window) points = [QPoint(100, 50), QPoint(50, 150), QPoint(150, 150)] painter.drawPolygon(QPolygon(points)) window.show() sys.exit(app.exec_())
import sys from PyQt4.QtGui import * app = QApplication(sys.argv) window = QWidget() window.setGeometry(100, 100, 200, 200) window.setStyleSheet("background-color: blue;") painter = QPainter(window) points = [QPoint(60, 0), QPoint(90, 50), QPoint(140, 60), QPoint(105, 100), QPoint(120, 150), QPoint(60, 120), QPoint(0, 150), QPoint(15, 100), QPoint(-20, 60), QPoint(30, 50)] painter.setBrush(QBrush(Qt.yellow)) painter.drawPolygon(QPolygon(points)) window.show() sys.exit(app.exec_())In this example, we first set the background color of the window to blue. We create a QPainter object and set the brush color to yellow, which will be used to fill the star. We define the vertices of the star by creating QPoint objects and adding them to a list. Finally, we call the drawPolygon method of the QPainter object and pass a QPolygon object created from the list of points. Overall, the PyQt4.QtGui library provides a powerful set of GUI components that can be used to create interactive applications with Python.