PyQt5入門(五)與Designer分手,開始轉向純程式碼構建
阿新 • • 發佈:2021-01-10
從本篇開始,就不再以designer為主來來進行學習了,而是轉向純py程式碼來實現程式的構建。
主視窗型別(3種):
import sys from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5.QtGui import QIcon #圖示 class FirstMainWin(QMainWindow): #self指標指向該類建立的例項物件 #parent指代實體的視窗物件,也就是主函式裡面那個mainWindow=QMainWindow() #兩個__int__(parent)中的parent加不加都無所謂 def __int__(self,parent=None): #呼叫父類初始化函式 super(FirstMainWin, self).__int__(parent) #設定著視窗的標題 self.setWindowTitle('first mainWindow app') #設定視窗的尺寸 self.resize(400,300) #獲得當前狀態列 self.status=self.statusBar() self.status.showMessage('a message that only exsits 5s',5000) if __name__=='__main__': app=QApplication(sys.argv) #設定應用程式圖示 app.setWindowIcon(QIcon('./icon/first.png')) main=FirstMainWin() main.show() #進入程式主迴圈 sys.exit(app.exec_())
有bug,除了圖示,類裡的功能感覺沒執行!!!!明天再說吧煩