网格布局警告DeprecationWarning

过时未解决
E:/pycharmProject/untitled4/QGridLayout.py:3: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead
class Demo(QWidget):

from PyQt5 import QtCore
from PyQt5.QtWidgets import *
class Demo(QWidget):
    def __init__(self,parent=None):
        # 这行代码调用了 QWidget 类的构造函数,以确保 Demo 类正确地继承了 QWidget 的属性和方法
        super(Demo,self).__init__(parent)
        self.initUI()

    def initUI(self):
        # 创建网格布局
        grid = QGridLayout()

        label1 = QLabel()
        label1.setText("用户名:")

        text1 = QLineEdit()

        label2 = QLabel()
        label2.setText("密码:")

        text2 = QLineEdit()

        btn1 = QPushButton()
        btn1.setText("登录")

        btn2 = QPushButton()
        btn2.setText("取消")

        # 在布局中添加控件
        grid.addWidget(label1,0,0,QtCore.Qt.AlignLeft)
        grid.addWidget(text1,0,1,QtCore.Qt.AlignLeft)
        grid.addWidget(label2,1,0,QtCore.Qt.AlignLeft)
        grid.addWidget(text2,1,1,QtCore.Qt.AlignLeft)
        grid.addWidget(btn1,2,0,QtCore.Qt.AlignLeft)
        grid.addWidget(btn2,2,1,QtCore.Qt.AlignLeft)

        # 设置网格布局
        self.setLayout(grid)

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec())

 

posted on 2024-12-21 15:43  无名高地  阅读(10)  评论(0编辑  收藏  举报