Punten tekenen
Op deze pagina:
Punten zijn de meest eenvoudige dingen om te tekenen.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys, random
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QColor, QPainter
class Venster(QWidget):
def __init__(self):
super(Venster, self).__init__()
self.initUI()
def initUI(self):
self.setGeometry(400, 400, 300, 180)
self.setWindowTitle('Punten')
self.show()
def paintEvent(self, e):
# Elk Painter event staat tussen .begin() en .end()
qp = QPainter()
qp.begin(self)
self.drawPoints(qp)
qp.end()
def drawPoints(self, qp):
qp.setPen(QColor(0, 0, 255))
size = self.size()
for i in range(1000):
x = random.randint(1, size.width()-1)
y = random.randint(1, size.height()-1)
qp.drawPoint(x, y)
def main():
app = QApplication(sys.argv)
window = Venster()
sys.exit(app.exec_())
if __name__ == '__main__':
main()