状态栏
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
class Myform(QMainWindow):
def __init__(self):
super(Myform, self).__init__()
self.initUI()
def initUI(self):
self.statusBar().showMessage('Ready')
self.setGeometry(300, 300, 200, 200)
self.setWindowTitle('status bar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Myform()
sys.exit(app.exec_())
菜单栏
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp
from PyQt5.QtGui import QIcon
class Myform(QMainWindow):
def __init__(self):
super(Myform, self).__init__()
self.initUI()
def initUI(self):
self.statusBar()
exitAction = QAction(QIcon('1.jpg'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
menuBar = self.menuBar()
QuitMenu = menuBar.addMenu('&Quit')
QuitMenu.addAction(exitAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('menubar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Myform()
sys.exit(app.exec_())
工具栏
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp
from PyQt5.QtGui import QIcon
class Myform(QMainWindow):
def __init__(self):
super(Myform, self).__init__()
self.initUI()
def initUI(self):
exitAction = QAction(QIcon('1.jpg'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
self.setGeometry(300, 300, 200, 150)
self.setWindowTitle('toolbar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Myform()
sys.exit(app.exec_())
综合
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QTextEdit
from PyQt5.QtGui import QIcon
class Myform(QMainWindow):
def __init__(self):
super(Myform, self).__init__()
self.initUI()
def initUI(self):
textEdit = QTextEdit()
self.setCentralWidget(textEdit)
exitAction = QAction(QIcon('1.jpg'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)
self.statusBar()
menuBar = self.menuBar()
QuitMenu = menuBar.addMenu('&Quit')
QuitMenu.addAction(exitAction)
toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
self.setGeometry(300, 300, 300, 210)
self.setWindowTitle('summary')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Myform()
sys.exit(app.exec_())