PyQT5視窗樣式設定

星空28發表於2024-06-09
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class WindowPattern(QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.resize(500, 300)
        self.setWindowTitle("設定視窗樣式")
        self.setWindowFlags(Qt.WindowMaximizeButtonHint | Qt.WindowStaysOnTopHint)

        # 最大化、最小化、關閉
        # self.setWindowFlags(Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint | Qt.WindowCloseButtonHint)
        self.setObjectName("MainWindow")
        self.setStyleSheet("#MainWindow{border-image:url(image/img1.png);}")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = WindowPattern()
    main.show()
    sys.exit(app.exec_())


相關文章