【发布时间】:2019-06-09 23:43:25
【问题描述】:
我在一个项目上工作:程序下载但我在使用 while 循环时遇到问题,用于检查与 Internet 的连接,如果 true 不 setText('') to lable 和 if Flase setText('anyText') to lable
连接检查方法
def checkInternetConnection(self,host="8.8.8.8", port=53, timeout=3):
while self.conection==False:
try:
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
self.conection = True
return self.conection
except Exception as e:
print(e)
self.label_9.setText('Please Check Internect Connection')
self.conection = False
return self.conection
self.finished.emit()
我已经厌倦了 QThread 。请问我该怎么做:)?如果连接丢失=False setText('check internet') 以及连接变为 true 时,应用程序正在运行时 setText('')
构造者
From_Class,_=loadUiType(os.path.join(os.path.dirname(__file__),'designe.ui'))
class mainApp(QMainWindow,From_Class):
finished = pyqtSignal()
def __init__(self,parent=None):
super(mainApp, self).__init__(parent)
QMainWindow.__init__(self)
super().setupUi(self)
self.handleGui()
self.handleButton()
self.setWindowIcon(QIcon('mainIcon.png'))
self.menuBarW()
self.conection = False
主代码
def main():
app = QApplication(sys.argv)
window = mainApp()
window.checkInternetConnection()
window.show()
app.exec()
if __name__=='__main__':
main()
【问题讨论】:
标签: python multithreading user-interface pyqt5