PyQt 应用程序和无限循环 [英] PyQt application and infinite loop

查看:75
本文介绍了PyQt 应用程序和无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def main():
    app = QtGui.QApplication(sys.argv)

    gui = GUIClass()
    gui.showUI()

    app.exec_()

    while True:
        if win32api.GetAsyncKeyState(win32con.VK_SHIFT):
            print(True)

if __name__ == '__main__':
    main()

app.exec_() 之后的代码没有运行.如何进行无限循环并运行我的 PyQt 应用程序?

Code after app.exec_() doesn't running. How to do infinite loop and run my PyQt application?

谢谢.

推荐答案

pyqt 带有自己的(无限)事件循环,因此您不必构建自己的事件循环.app.exec_() 进入这个循环,这就是为什么你看不到执行之后的代码.只有在关闭所有 qt 窗口后,才会执行剩余的任何内容.

pyqt comes with its own (infinite) event loop so that you don't have to build your own. app.exec_() enters this loop, which is why you don't see the code following that execute. Only after you have closed all qt windows will anything remaining be executed.

QTimer 使用示例:

Example of QTimer usage:

main()之前exec_():

def timout():
    if win32api.GetAsyncKeyState(win32con.VK_SHIFT):
        print(True)

timer = QtCore.QTimer(self)
timer.timeout.connect(timeout)
timer.start(100)

这篇关于PyQt 应用程序和无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆