QVBoxLayout organizes your widgets vertically in a window.
Instead of organizing all the widgets yourself (specifying the geographic location), you can let PyQt take care of it.
Every new widget you add with
.addWidget(), is added vertically. Basically you get a vertical list of your widgets. Each new widget is added to the bottom of the list.
Related Course: Create GUI Apps with Python PyQt5
The simple example below creates a
QVboxLayout. Then uses the method
addWidget, which adds the newly created buttons in vertical direction.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
This creates this app:
The parameter in addWidget() accepts any widget in PyQt5.QtWidgets like QPushButton and all the other available widgets.
Don’t forget to add the QVBoxLayout to the window with