-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcodes_9.py
More file actions
47 lines (33 loc) · 1.18 KB
/
codes_9.py
File metadata and controls
47 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# codes_9.py
import sys
from PyQt4 import QtGui, QtCore
class MySignal(QtCore.QObject):
# This class defines the new signal 'signal_writer'
signal_writer = QtCore.pyqtSignal()
class MyForm(QtGui.QWidget):
def __init__(self):
super().__init__()
self.initialize_GUI()
def initialize_GUI(self):
self.s = MySignal()
self.s.signal_writer.connect(self.write_label)
self.label1 = QtGui.QLabel('Label', self)
self.label1.move(20, 10)
self.resize(self.label1.sizeHint())
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Signal Emitter')
self.show()
def mousePressEvent(self, event):
# This method handles when any of the mouse buttons is pressed. It is
# defined by default within the app. It can be overwritten according
# to how the event should be handled in each app.
self.s.signal_writer.emit()
def write_label(self):
self.label1.setText('Mouse was clicked')
self.label1.resize(self.label1.sizeHint())
def main():
app = QtGui.QApplication(sys.argv)
ex = MyForm()
sys.exit(app.exec_())
if __name__ == '__main__':
main()