TLDR why do people create classes (Window for example) when its only going to be used once?
Some examples:
RealPython, the first code block
PythonBasics, first code block
PythonPyQt, first code block
Why can't they put the code in the main program (using the RealPython example):
if __name__ == "__main__":
window = Qwidget.setWindowTitle("QHBoxLayout Example")
window.show()
# Create a QHBoxLayout instance
layout = QHBoxLayout()
# Add widgets to the layout
layout.addWidget(QPushButton("Left-Most"))
layout.addWidget(QPushButton("Center"), 1)
layout.addWidget(QPushButton("Right-Most"), 2)
# Set the layout on the application's window
window.setLayout(layout)
print(window.children())
sys.exit(app._exec())
Instead of
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QHBoxLayout Example")
# Create a QHBoxLayout instance
layout = QHBoxLayout()
# Add widgets to the layout
layout.addWidget(QPushButton("Left-Most"))
layout.addWidget(QPushButton("Center"), 1)
layout.addWidget(QPushButton("Right-Most"), 2)
# Set the layout on the application's window
self.setLayout(layout)
print(self.children())
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())