QWidget::setLayout: Attempting to set QLayout "" on Window "", which already has a layout

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QApplication, QWidget, QMainWindow,
QVBoxLayout, QHBoxLayout, QFormLayout, QGridLayout, QStackedLayout,
QPushButton, QComboBox, QLineEdit, QCheckBox, QRadioButton,
)
class Window(QWidget):
def init(self):
super().init()

    layVer = QVBoxLayout()
    self.comBox = QComboBox()
    self.comBox.addItems(["One", "Two", "Three"])
    self.comBox.activated.connect(lambda x: self.onComBox(x))
    layVer.addWidget(self.comBox)
    self.setLayout(layVer)

    layHor = QHBoxLayout()
    self.cheBox1 = QCheckBox("A")
    layHor.addWidget(self.cheBox1)
    self.setLayout(layHor)

    layVer.addLayout(layHor)

def onCheBox(self, s):
    print(s)

def onComBox(self, s):
    print(s, self.comBox.currentText())

if name == “main”:
app = QApplication([])
win = Window()
win.show()
app.exec_()

I am a Beginner. I do not understand this error message. Who can explain it to me. :slight_smile:

Hello, @Ali_Sanawi_Garrousi, welcome to the forum! :slight_smile:

Firstly, delete the line
self.setLayout(layVer)

then fix

self.setLayout(layHor)

layVer.addLayout(layHor)

to be

layVer.addLayout(layHor)

self.setLayout(layVer)

Merci now it works :blush: