May 2019
Intermediate to advanced
542 pages
13h 37m
English
For the board GUI, we'll use a QGraphicsScene object just as we did for our tank game in Chapter 12, Creating 2D Graphics with QPainter.
We'll start with some class variables:
class TTTBoard(qtw.QGraphicsScene): square_rects = ( qtc.QRectF(5, 5, 190, 190), qtc.QRectF(205, 5, 190, 190), qtc.QRectF(405, 5, 190, 190), qtc.QRectF(5, 205, 190, 190), qtc.QRectF(205, 205, 190, 190), qtc.QRectF(405, 205, 190, 190), qtc.QRectF(5, 405, 190, 190), qtc.QRectF(205, 405, 190, 190), qtc.QRectF(405, 405, 190, 190) ) square_clicked = qtc.pyqtSignal(int)
The square_rects tuple defines a QRectF object for each of the nine squares on the board, and a square_clicked signal is emitted whenever a square is clicked on; the accompanying integer will ...
Read now
Unlock full access