1. 基本窗口
import sys
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QWidget()
widget.resize(360, 360)
widget.setWindowTitle("hello, pyqt5")
widget.show()
sys.exit(app.exec_())
2. 状态栏
import sys
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
mainwindow = QtWidgets.QMainWindow()
mainwindow.setWindowTitle("QMainWindow demo")
mainwindow.resize(400, 200)
mainwindow.status = mainwindow.statusBar()
mainwindow.status.showMessage("status bar",5000)
mainwindow.show()
sys.exit(app.exec_())
3. 设置窗口图标
import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget , QApplication
class Icon(QWidget):
def __init__(self, parent = None):
super(Icon,self).__init__(parent)
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('window icon')
self.setWindowIcon(QIcon("./resource/github.png"))
if __name__ == '__main__':
app = QApplication(sys.argv)
icon = Icon()
icon.show()
sys.exit(app.exec_())
4. 设置气泡
import sys
from PyQt5.QtWidgets import QWidget, QToolTip , QApplication
from PyQt5.QtGui import QFont
class Winform(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
QToolTip.setFont(QFont('SansSerif', 10))
self.setToolTip('This is <b>tip </b>')
self.setGeometry(200, 300, 400, 400)
self.setWindowTitle('tool tip demo')
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Winform()
win.show()
sys.exit(app.exec_())