PyQt5 set background image for window

The QPalette class can easily achieve the purpose of setting the window background image

def use_palette(self): 
    self.setWindowTitle("设置背景图片") 
    window_pale = QtGui.QPalette() 
    window_pale.setBrush(self.backgroundRole(),   QtGui.QBrush(QtGui.QPixmap("F:\A_code\PyQT_Demo\\back_ground.png"))) 
    self.setPalette(window_pale)

write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325568742&siteId=291194637