Python Forum
A dynamically updating GUI screen from URL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A dynamically updating GUI screen from URL
#18
(Apr-16-2019, 02:55 PM)Alfalfa Wrote: Here you define data with "data = s.recv(1024)". When you move the code related to connection into it's own method, make sure you still define 'data' before trying to emit the signal. In other words, don't emit the signal unless the data variable exist.

import sys, time, socket
from PyQt5 import QtWidgets, QtCore
HOST = '192.168.1.33' 
PORT = 80             

class WorkerThread(QtCore.QObject):
    signal = QtCore.pyqtSignal(int)
 
    def __init__(self):
        super().__init__()

    @QtCore.pyqtSlot()
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                s.connect((HOST, PORT))
                s.sendall(b'Hello, world')
    def run(self):
        while True:
            data = s.recv(1024)  
            print('Received distance value', repr(data)) 
            self.signal.emit(int(data))  
            #time.sleep(0.1)
Error:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: ^ IndentationError: unexpected indent
It should give data result in while with timer, but it should not try to connect server every while loop.
Reply


Messages In This Thread
RE: A dynamically updating GUI screen from URL - by bescf - Apr-17-2019, 01:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A dynamically updating screen for PyQt GUI from URL bescf 0 2,675 Mar-25-2019, 06:58 AM
Last Post: bescf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020