用面向过程实现
import sys
from PyQt5.QtWidgets import QApplication, QWidget
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QWidget()
w.resize(400, 200)
w.move(300, 300)
w.setWindowTitle('第一个基于PyQt5的桌面应用')
w.show()
sys.exit(app.exec_())
面向对象实现
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class FirstMainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('第一个窗口应用')
self.resize(400, 300)
self.status = self.statusBar()
self.status.showMessage('只存在五秒的消息', 5000)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = FirstMainWindow()
main.show()
sys.exit(app.exec_())