Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5.QtWidgets import *
- from PyQt5.QtCore import *
- from socket import *
- import time
- class Socket(QThread):
- def __init__(self, parent=None):
- super().__init__()
- self.i = 1
- def run(self):
- while True:
- global c
- try:
- c = socket(AF_INET, SOCK_STREAM)
- c.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
- c.connect(('192.168.0.57', 8080))
- break
- except:
- print('Reconnetion... #', self.i)
- time.sleep(1)
- self.i = self.i + 1
- print('test')
- class MyWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.setupUI()
- def setupUI(self):
- self.setGeometry(800, 200, 300, 300)
- self.label = QLabel()
- layout = QVBoxLayout()
- layout.addWidget(self.label)
- self.setLayout(layout)
- self.socket = Socket()
- self.socket.start()
- '''
- class MyMainWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- wg = MyWidget()
- self.setCentralWidget(wg)
- self.show()
- '''
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- mywindow = MyWidget()
- mywindow.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement