Python GUI布局方式:
绝对定位布局(move())
水平盒(QHBoxLayout())
垂直盒(QVBoxLayout())
网格布局(QGridLayout())
表单布局(QFormLayout())
一、绝对定位布局
每个控件通过move()设定具体位置
实例:
import sysfrom PyQt5.QtWidgets import QApplication, QWidgetclass Demo(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): label1 = QLabel('demo1',self) label1.move(10,20) label2 = QLabel('demo2',self) label2.move(10,40) label3 = QLabel('demo3', self) label3.move(10, 60) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('绝对定位') self.show()if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
效果: