PyQt5菜單添加+事件+狀態列-7

來源:互聯網
上載者:User

標籤:code   widget   try   file   sys   ica   widgets   port   com   

 1 from PyQt5.QtWidgets import QApplication,QMainWindow,QAction 2 from PyQt5.QtGui import QIcon 3 #demo_7:菜單添加action以及狀態列顯示訊息 4 import sys 5 class Example(QMainWindow): 6     def __init__(self): 7         self.app = QApplication(sys.argv) 8         super().__init__() 9         self.initUI()10 11     def initUI(self):12         action=QAction(QIcon(‘exit.png‘),‘&exit‘,self) #定義一個Action即動作13         action.setStatusTip(‘Exit application‘)#狀態列資訊14         action.triggered.connect(self.app.quit) #觸發事件動作為"關閉視窗"15         action.setShortcut(‘Ctrl+Q‘)#快速鍵設定16         self.statusBar()#狀態列信17 18         menu=self.menuBar() #當前表單建立menuBar19         fmenu=menu.addMenu(‘&file‘)20 21         menu2 = self.menuBar()22         fmenu2 = menu2.addMenu(‘&test‘) #再添加一個menuBar23 24         fmenu.addAction(action) #為第一層級menu添加動作25         self.setGeometry(300, 300, 300, 200)26         self.setWindowTitle(‘Statusbar‘)27         self.show()28 29 if __name__==‘__main__‘:30 31     e=Example()32     sys.exit(e.app.exec())

 

PyQt5菜單添加+事件+狀態列-7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.