如何在PyQt4中禁用按钮(或整个主窗口),直到函数返回0

0 投票
1 回答
925 浏览
提问于 2025-05-10 20:55

我有一个网页抓取脚本,叫做 scraper.py,它会把数据写入数据库。我还做了一个图形界面,里面有一个表格控件,可以显示数据库的内容。现在,我添加了一个按钮,这个按钮会调用 scraper.py 脚本里的 main() 函数。因为这个抓取程序使用了 selenium,整个过程大约需要 20 秒钟才能完成(包括打开和关闭浏览器),所以我希望在 scraper.py 完成之前,这个按钮(或者整个叫 MainWindow 的表单)都不能被点击。

另外,main() 函数不一定需要有一个 'return 0' 的语句。

提前谢谢你。

相关文章:

  • 暂无相关问题
暂无标签

1 个回答

1
def fetchFuction():
    QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
    # if incase function failed then restore it
    try:
        yourFetchFucn()
        QtGui.QApplication.restoreOverrideCursor()
    except:
        QtGui.QApplication.restoreOverrideCursor()

希望这能帮到你

撰写回答