通过下面的一个PyQt5简单例子,来简单了解一下关于如何创建PyQt5的。具体代码如下:
#-*- coding:utf-8 -*-
'''
Frist PyQt5 program
'''
__author__ = 'Tony Zhu'
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout, QPushButton, QLineEdit, QVBoxLayout,QMessageBox
import sys
class ShowWindow(QWidget):
def __init__(self):
super(ShowWindow,self).__init__()
self.initUI()
def initUI(self):
self.inputLabel = QLabel("Input your text")
self.editLine = QLineEdit()
self.printButton = QPushButton("Print")
self.clearButton = QPushButton("Clear")
self.printButton.clicked.connect(self.printText)
self.clearButton.clicked.connect(self.clearText)
inputLayout = QHBoxLayout()
inputLayout.addWidget(self.inputLabel)
inputLayout.addWidget(self.editLine)
buttonLayout = QHBoxLayout()
buttonLayout.addWidget(self.printButton)
buttonLayout.addWidget(self.clearButton)
mainLayout = QVBoxLayout()
mainLayout.addLayout(inputLayout)
mainLayout.addLayout(buttonLayout)
self.setLayout(mainLayout)
self.setWindo