使用.move將控件水平移動到特定的位置, 被稱為絕對布局
AbsoluteLayout.py
""" 絕對布局 """ import sys, math from PyQt5.QtWidgets import * class AbsoluteLayout(QWidget): def __init__(self): super(AbsoluteLayout, self).__init__() self.setWindowTitle("絕對布局") self.label1 = QLabel('歡迎', self) self.label1.move(15, 20) self.label2 = QLabel('學習', self) self.label2.move(35, 40) self.label3 = QLabel('PyQt5', self) self.label3.move(55, 80) if __name__ == "__main__": app = QApplication(sys.argv) main = AbsoluteLayout() main.show() sys.exit(app.exec_())