简体   繁体   English

Python PyQt5 创建布局

[英]Python PyQt5 Create Layout

I'm trying to create a layout with pyqt5, but i cannot do it.我正在尝试使用 pyqt5 创建布局,但我无法做到。 There are so many error.有这么多错误。 Why i am getting so many errors.为什么我收到这么多错误。

代码和错误

autoFillBackground() takes no arguments, and MainWindow will not assume the palette of it's central widget unless you explicitly set it. autoFillBackground()接受任何参数,除非您明确设置,否则MainWindow不会假定它的中央小部件的调色板。 Also, this has nothing to do with a layout.此外,这与布局无关。

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class Color(QWidget):

    def __init__(self, color):
        super().__init__()
        self.autoFillBackground()
        palette = self.palette()
        palette.setColor(QPalette.Window, QColor(color))
        self.setPalette(palette)

class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()
        widget = Color('Blue')
        self.setCentralWidget(widget)
        self.setPalette(widget.palette())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM