#!/usr/bin/python3# -*- coding: utf-8 -*-"""
Py40 PyQt5 tutorial
In this example, we connect a signal
of a QSlider to a slot of a QLCDNumber.
author: Jan Bodnar
website: py40.com
last edited: January 2015
"""import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import(QWidget, QLCDNumber, QSlider,
QVBoxLayout, QApplication)classExample(QWidget):def__init__(self):super().__init__()
self.initUI()definitUI(self):
lcd = QLCDNumber(self)
sld = QSlider(Qt.Horizontal, self)
vbox = QVBoxLayout()
vbox.addWidget(lcd)
vbox.addWidget(sld)
self.setLayout(vbox)
sld.valueChanged.connect(lcd.display)
self.setGeometry(300,300,250,150)
self.setWindowTitle('Signal & slot')
self.show()if __name__ =='__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
#!/usr/bin/python3# -*- coding: utf-8 -*-"""
pyu40 PyQt5 tutorial
In this example, we reimplement an
event handler.
author: Jan Bodnar
website: py40.com
last edited: January 2015
"""import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication
classExample(QWidget):def__init__(self):super().__init__()
self.initUI()definitUI(self):
self.setGeometry(300,300,250,150)
self.setWindowTitle('Event handler')
self.show()defkeyPressEvent(self, e):if e.key()== Qt.Key_Escape:
self.close()if __name__ =='__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())