如何在PyQt中将按钮设置为键盘中断 [英] How to set push-button to keyboard interrupt in PyQt

查看:169
本文介绍了如何在PyQt中将按钮设置为键盘中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过终端运行程序时,我们可以通过按"Ctrl + c"来停止程序,它将显示为"KeyboardInterrupt"消息.因此,有什么方法可以通过单击PyQt中的按钮来做理智的事情.

While running program through the terminal we can stop the program by pressing 'Ctrl+c' and it will show the message as 'KeyboardInterrupt' . So, is there any way to do the sane thing by clicking the push-button in PyQt.

推荐答案

如果程序正在运行循环,则可以调用

If your program is running a loop, you can call processEvents periodically to allow the gui time to update (which should allow you to click a button to close the application):

    count = 0
    while True:
         count += 1
         if not count % 50:
             QtGui.qApp.processEvents()
         # do stuff...

这篇关于如何在PyQt中将按钮设置为键盘中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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