码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt5 初始

时间:2018-01-05 19:51:24      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:imp   res   log   sys.argv   core   ati   sel   name   exe   

import sys
from PyQt5.QtWidgets import (QWidget, QToolTip,QMessageBox,
QPushButton, QApplication,QDesktopWidget)
from PyQt5.QtGui import QFont,QIcon
from PyQt5.QtCore import QCoreApplication


class Example(QWidget):

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(50, 50)

btn.clicked.connect(QCoreApplication.instance().quit)

self.setGeometry(300, 300, 300, 200)
self.setWindowTitle(‘Tooltips‘)
self.setWindowIcon(QIcon(‘y7.png‘))
self.center()

self.show()

def center(self):

qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def closeEvent(self, event):

reply = QMessageBox.question(self, ‘Message‘,
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)

if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()


if __name__ == ‘__main__‘:
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

pyqt5 初始

标签:imp   res   log   sys.argv   core   ati   sel   name   exe   

原文地址:https://www.cnblogs.com/xiesongyou/p/8206302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!