欢迎来我的博客

PyQt5 给无边框widget窗口添加背景图片

PyQt5 给无边框widget窗口添加背景图片

#! /usr/bin/env python

# -*- coding:utf-8 -*-

import sys

from PyQt5.QtWidgets import QApplication, QWidget

from PyQt5.QtCore import Qt

from PyQt5.QtGui import QPalette, QBrush, QPixmap

class NoBorderWindow(QWidget):

    def __init__(self):

        super().__init__()

        self.window_UI()

        self.drawn()   

    def window_UI(self):

        self.resize(950, 200) 

        self.setWindowFlags(Qt.FramelessWindowHint)

    def drawn(self):

        self.palette = QPalette()

        self.palette.setBrush(QPalette.Background, QBrush(QPixmap("./images/bg.gif")))

        self.setPalette(self.palette)



if __name__ == "__main__":

    app = QApplication(sys.argv)

    win = NoBorderWindow()    

    win.show()

    sys.exit(app.exec_())

 

 

posted on 2020-05-01 14:18  tylerwu  阅读(2518)  评论(0编辑  收藏  举报

导航