-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtestapp.py
37 lines (25 loc) · 877 Bytes
/
testapp.py
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
#!/usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui
def make_handler(i):
def handler():
print('Button {} was pressed'.format(i))
return handler
def main():
print('TestApp argv:', sys.argv)
app = QtGui.QApplication([])
dialog = QtGui.QDialog()
dialog.setLayout(QtGui.QVBoxLayout())
button1 = QtGui.QPushButton('Click me1', dialog, objectName='but1')
button1.pressed.connect(make_handler(1))
dialog.layout().addWidget(button1)
button2 = QtGui.QPushButton('Click me2', dialog, objectName='but2')
button2.pressed.connect(make_handler(2))
dialog.layout().addWidget(button2)
dialog.show()
# When the app is tested with PyQtTester, the exit here is skipped ...
sys.exit(app.exec())
# ... this is printed instead.
print('TestApp says: Bye bye.')
if __name__ == '__main__':
main()