Use vertical layout method the same as horizontal layout
Also use the designer to design the ui, then convert it to py, and then write the following code for display
import sys
import vertical_layout_demo
from PyQt5.QtWidgets import QApplication,QMainWindow
if __name__ == '__main__':
# 创建运行程序
app = QApplication(sys.argv)
# 创建主窗口
mainwindow = QMainWindow()
ui = vertical_layout_demo.Ui_MainWindow()
# 向主窗口中添加控件
ui.setupUi(mainwindow)
mainwindow.show()
sys.exit(app.exec_())
Effect:
![](https://img-blog.csdnimg.cn/img_convert/6e86ced3442843ab9c2a84dfaa3dd849.png)