#!/usr/bin/python
# quitbutton.py
import sys
from PyQt4 import QtGui, QtCore
class StatusBar(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.initGUI()
def initGUI(self):
self.statusBar().showMessage('Hello,statusBar')
self.statusBar().showMessage('This is second statusBar')
self.setGeometry(300,300,250,150)
self.setWindowTitle('StatusBar')
def main():
app = QtGui.QApplication(sys.argv)
widget = StatusBar()
widget.show()
sys.exit(app.exec_())
要创建一个状态栏,我们需要使用QMainWindow这个类。StatusBar类继承了QMainWindow类之后,我们可可以用它创建一个状态栏,创建状态栏的方法是调用statusBar()方法。然后,为了在状态栏中显示信息,再调用showMessage()方法。特别注意:在上面的代码中,写了两行显示信息的代码,从运行结果来看,状态栏中显示的是‘This is second statusBar’