PyQt5笔记(05) -- 绝对位置

时间:2021-02-12 23:01:29

本节主要介绍PyQt5里绝对位置的使用

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QMainWindow
from PyQt5.QtGui import QIcon

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title = 'PyQt absolute positioning'
        self.left = 30
        self.top = 30
        self.width = 440
        self.height = 280
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        label = QLabel('Python', self)
        label.move(50, 50)

        label2 = QLabel('PyQt5', self)
        label2.move(100, 100)

        label3 = QLabel('Examples', self)
        label3.move(150,150)

        label4 = QLabel('pytonspot.com', self)
        label4.move(200,200)

        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

效果如下:
PyQt5笔记(05) -- 绝对位置