Answers for "pyqt5 change main window background color"

1

pyqt change background color

class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_me()

    def init_me(self):
        self.setGeometry(600, 250, 750, 500)
        self.setStyleSheet("background:gray")  <----
        # or
        # self.setStyleSheet("background:rgb(r:int,g:int,b:int)")  <----

        self.show()
        
# to change the color of the text:
# self.setStyleSheet("color:rgb(...)")
# or to change both at the same time:
# self.setStyleSheet("color: rgb(...);background: rgb(...)")
# you can do that with any QWidget object or class that inherits QWidget,
# eg. QPushButton, QLabel, ...
Posted by: Guest on September-18-2020
0

how to add window background in pyqt5

stylesheet = """
    MainWindow {
        background-image: url("D:/_Qt/img/cat.jpg"); 
        background-repeat: no-repeat; 
        background-position: center;
    }
"""
Posted by: Guest on November-30-2020

Code answers related to "pyqt5 change main window background color"

Python Answers by Framework

Browse Popular Code Answers by Language