python使用不同函数调用一个函数,有一个发生未响应?

先写了一个按钮点击槽函数,用这个调用createNewWidget自定义函数时,setCurrentIndex的步骤是不会卡死的,而用printhello函数调用时,明显每次都出现在setCurrentIndex的卡死,该如何理解和解决呢?

    def createNewWidget(self):
        global widnum
        global newPath
        print('已有'+ (str)(widnum) + '个窗口,现新建一个')
        widgetName = 'Widget' + (str)(widnum)
        print('新建窗口名' + widgetName)

        exec(widgetName + " = MyWidget()")
        print('?')
        exec('self.boardLayout.addWidget('+ widgetName + ')')
        print('?')# ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓出问题 ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓
        self.boardLayout.setCurrentIndex(widnum) 
        print('?')         
        print('当前顶层窗口索引'+(str)(self.boardLayout.currentIndex()))
        widnum += 1
        newPath = 0
        self.printHello()

两个调用它的函数

        # 放在一个自定义类的initui方法里
        btnNew = QPushButton('新建图层')
        btnNew.clicked.connect(self.createNewWidget)

    def printHello(self):
        global newPath
        global lastPath
        print('helloworld')
        if newPath:
            self.createNewWidget()
        else:
            t = Timer(5, self.printHello)
            t.setDaemon(True)
            t.start()

因为你的printHello是在timer里执行的,这是另一个线程
子线程操作UI必须通过委托,不可以直接修改UI