• 欢迎光临~

PyQt5 QObject-对象类型判定和控件继承类型

开发技术 开发技术 2022-05-31 次浏览
'''
        isWidgetType()  # 判断类型
        inherits('')  # 是否继承与某个类
'''
 
from PyQt5.Qt import *
import sys
 
class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("类型判定")
        self.resize(600,500)
        self.func_list()
 
    def func_list(self):
        self.func()
 
 
    def func(self):
        obj = QObject()
        win = QWidget()
        btn = QPushButton()
        label = QLabel()
 
        obj_list = [obj, win, btn, label]
        for o in obj_list:
            # print(o.isWidgetType())
            print(o.inherits('QPushButton'))
 
 
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
 
    window.show()
    sys.exit(app.exec_())

 【全套】PyQt5教程_PyQt5菜鸟教程 - python GUI编程网 (bl186.net)

程序员灯塔
转载请注明原文链接:PyQt5 QObject-对象类型判定和控件继承类型
喜欢 (0)