Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- import sys
- from PyQt5.QtWidgets import *
- from PyQt5.QtGui import *
- from PyQt5.QtCore import QCoreApplication
- class Example(QMainWindow):
- def __init__(self):
- super().__init__()
- self.initUI()
- def initUI(self):
- QToolTip.setFont(QFont('SansSerif', 10))
- self.setToolTip('This is a <b>QWidget</b> widget')
- btn = QPushButton('Закрыть программу', self)
- btn.setToolTip('This is a <b>QPushButton</b> widget')
- btn.resize(btn.sizeHint())
- btn.move(100, 100)
- btn.clicked.connect(QCoreApplication.instance().quit)
- self.setGeometry(300, 300, 400, 250)
- self.setWindowTitle('Бесполезная программа')
- self.show()
- exitAction = QAction(QIcon('web.ico'), '&Exit', self)
- exitAction.setShortcut('Ctrl+Q')
- exitAction.setStatusTip('Exit')
- exitAction.triggered.connect(qApp.quit)
- printAction = QAction(QIcon('web.ico'), 'Printhello', self)
- printAction.setShortcut('Ctrl+H')
- printAction.setStatusTip('print Hello')
- printAction.triggered.connect(self.printhello)
- self.statusBar()
- menubar = self.menuBar()
- fileMenu = menubar.addMenu('&File')
- fileMenu.addAction(exitAction)
- optionsMenu = menubar.addMenu('&Options')
- optionsMenu.addAction(printAction)
- def closeEvent(self, event):
- reply = QMessageBox.question(self, 'Выход', "Закрыть программу?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
- if reply == QMessageBox.Yes:
- event.accept()
- else:
- event.ignore()
- def printhello(self):
- print('Hello!')
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement