datetime:2019/5/20 14:04
author:nzb
创建按钮
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QDesktopWidget, QPushButton
from PyQt5 import QtGui
from PyQt5 import QtCore
class UI_demo(QMainWindow):
"""用户界面"""
def __init__(self):
super().__init__()
self.title = 'PyQt5 demo'
self.left = 600
self.top = 200
self.width = 800
self.height = 600
self.initWindow()
def initWindow(self):
self.setWindowIcon(QtGui.QIcon('../img/home.ico'))
self.setGeometry(self.left, self.top, self.width, self.height)
self.setWindowTitle(self.title)
self.button()
self.show()
def button(self):
"""按钮"""
btn = QPushButton('click me', self)
btn.setGeometry(QtCore.QRect(300, 250, 150, 34))
btn.setIcon(QtGui.QIcon('../img/Agt Stop.ico'))
btn.setIconSize(QtCore.QSize(40, 40))
btn.setToolTip('按钮提示')
btn.clicked.connect(self.ClickMe)
def ClickMe(self):
print('Hello World')
sys.exit()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = UI_demo()
sys.exit(app.exec_())