Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. from PyQt5.QtWidgets import *
  5. from PyQt5.QtGui import *
  6. from PyQt5.QtCore import QCoreApplication
  7. class Example(QMainWindow):
  8.  
  9. def __init__(self):
  10. super().__init__()
  11. self.initUI()
  12.  
  13.  
  14. def initUI(self):
  15. QToolTip.setFont(QFont('SansSerif', 10))
  16.  
  17. self.setToolTip('This is a <b>QWidget</b> widget')
  18.  
  19. btn = QPushButton('Закрыть программу', self)
  20. btn.setToolTip('This is a <b>QPushButton</b> widget')
  21. btn.resize(btn.sizeHint())
  22. btn.move(100, 100)
  23. btn.clicked.connect(QCoreApplication.instance().quit)
  24.  
  25. self.setGeometry(300, 300, 400, 250)
  26. self.setWindowTitle('Бесполезная программа')
  27. self.show()
  28.  
  29. exitAction = QAction(QIcon('web.ico'), '&Exit', self)
  30. exitAction.setShortcut('Ctrl+Q')
  31. exitAction.setStatusTip('Exit')
  32. exitAction.triggered.connect(qApp.quit)
  33.  
  34. printAction = QAction(QIcon('web.ico'), 'Printhello', self)
  35. printAction.setShortcut('Ctrl+H')
  36. printAction.setStatusTip('print Hello')
  37. printAction.triggered.connect(self.printhello)
  38.  
  39. self.statusBar()
  40. menubar = self.menuBar()
  41.  
  42. fileMenu = menubar.addMenu('&File')
  43. fileMenu.addAction(exitAction)
  44. optionsMenu = menubar.addMenu('&Options')
  45. optionsMenu.addAction(printAction)
  46.  
  47.  
  48. def closeEvent(self, event):
  49. reply = QMessageBox.question(self, 'Выход', "Закрыть программу?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  50. if reply == QMessageBox.Yes:
  51. event.accept()
  52. else:
  53. event.ignore()
  54. def printhello(self):
  55. print('Hello!')
  56.  
  57.  
  58. if __name__ == '__main__':
  59. app = QApplication(sys.argv)
  60. ex = Example()
  61. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement