aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/tutorials/cannon/t11.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/tutorials/cannon/t11.py')
-rw-r--r--examples/widgets/tutorials/cannon/t11.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/examples/widgets/tutorials/cannon/t11.py b/examples/widgets/tutorials/cannon/t11.py
index ea8e53a8e..fa2198e10 100644
--- a/examples/widgets/tutorials/cannon/t11.py
+++ b/examples/widgets/tutorials/cannon/t11.py
@@ -159,13 +159,10 @@ class CannonField(QWidget):
self.update(region)
def paintEvent(self, event):
- painter = QPainter(self)
-
- self.paint_cannon(painter)
- if self._auto_shoot_timer.isActive():
- self.paint_shot(painter)
- # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3.
- painter.end()
+ with QPainter(self) as painter:
+ self.paint_cannon(painter)
+ if self._auto_shoot_timer.isActive():
+ self.paint_shot(painter)
def paint_shot(self, painter):
painter.setPen(Qt.NoPen)