一直沉迷工作,没时间写博客(借口?),最近公司休假,偷得浮生半日闲,把以前在Evernote上保存的笔记都分享出来,发表成博客,以共勉。
好了下面从hello-world开始简单介绍:
import sys
from PyQt5 import QtWidgets
class MyWindow(QtWidgets.QWidget):
def __init__(self):
super(MyWindow, self).__init__()
def startMe():
app = QtWidgets.QApplication(sys.argv)
w = MyWindow()
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
startMe()
----------------
下面再讲一下mainwindow一些用法:
from PyQt5 import QtWidgets, QtCore
from uwnd1 import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow,QMessageBox
import sys
class MyWnd(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MyWnd, self).__init__()
self.setupUi(self)
def openmsg(self):
res = QMessageBox.information(self, "打开", "U clicked.",
QMessageBox.StandardButtons(QMessageBox.Yes))
# statusBar()是QMainWindow类自带的,首次运行此方法时,会自动检测状态栏是否存在并自动生成.
self.statusBar().showMessage("状态栏: I am showing... ")
def startMe():
app = QtWidgets.QApplication(sys.argv)
dlg = MyWnd()
dlg.show()
sys.exit(app.exec_())
if __name__ == "__main__":
startMe()
最后结果如下: