我使用self.close
关闭正在运行的小部件。整个代码如下:
class timeTracker(QWidget):
'''time tracker main application v_0.8'''
def __init__(self, parent=None):
super(timeTracker, self).__init__(parent)
self.grid = QGridLayout()
self.setLayout(self.grid)
while not self.connectivity():
print(self.connectivity())
ret = QMessageBox.warning(self, "Not connected to network. Please check the connection", "", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if ret == QMessageBox.No:
self.close()
qApp.quit()
break
qApp.quit()
# self.time_widget = timeline.timeWidget()
# self.grid.addWidget(self.time_widget, 0, 0)
def connectivity(self):
try:
urllib.request.urlopen("http://www.google.com", timeout=1)
return True
except urllib.error.URLError as error:
return False
if __name__ == "__main__":
application = QApplication(sys.argv)
main_widget = timeTracker()
main_widget.show()
main_widget.move(10, 10)
sys.exit(application.exec_())
我从这段代码中期望的是,只要连接函数返回True,如果用户单击yes,就会反复要求他们执行特定的操作。如果他们单击“否”,我将终止整个小部件。但当我单击“否”时,它只会穿过自动关闭. 我该怎么做才能真正终止程序?你知道吗
要像本例中那样强制关闭应用程序,我们可以使用^{}
相关问题 更多 >
编程相关推荐