Pyqt5保持窗体在前台

关键代码

from PyQt5.QtWidgets import QApplication, QMainWindow
import PyQt5.QtCore
myWin.setWindowFlags(PyQt5.QtCore.Qt.WindowMinimizeButtonHint |  # 使能最小化按钮
                         PyQt5.QtCore.Qt.WindowCloseButtonHint |  # 使能关闭按钮
                         PyQt5.QtCore.Qt.WindowStaysOnTopHint)  # 窗体总在最前端

 

例如

if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWin = MyWindow()
    myWin.pushButton.clicked.connect(myWin.Refrensh)
    myWin.pushButton_2.clicked.connect(myWin.Main_to)
    myWin.setWindowFlags(PyQt5.QtCore.Qt.WindowMinimizeButtonHint |  # 使能最小化按钮
                         PyQt5.QtCore.Qt.WindowCloseButtonHint |  # 使能关闭按钮
                         PyQt5.QtCore.Qt.WindowStaysOnTopHint)  # 窗体总在最前端
    myWin.show()
    myWin.comboBox.addItems(myWin.GetAllWinHwn().keys())
    sys.exit(app.exec_())

就是可以使窗体一直保持在前台显示啦

你可能感兴趣的:(python,可视化,Pyqt5)