How to link an Analog Var with Qt Lcd Number

Solution for How to link an Analog Var with Qt Lcd Number
is Given Below:

i am working on a small project
I have a potentiometer witch provide analog data via a serial com (like it’s shown on the Com_Serial file )
so I want to read the data on the variable ‘f’ and show it on the QT lcd number

the interface File :

import sys
from PyQt5.QtWidgets import*
from PyQt5 import uic
from PyQt5 import*
from Com_Serial import f

class AppDemo(QWidget):

def __init__(self):
    super().__init__()
    uic.loadUi('app.ui', self)
    self.Motor_Speed_Lcd.display(f)


if __name__ == '__main__':
app = QApplication(sys.argv)
demo = AppDemo()
demo.show()
try:
    sys.exit(app.exec_())
except SystemExit:
    print('Closing Window…')

the Com_Serial File :

import serial
ser= serial.Serial(port="com4", baudrate=115200, timeout=1)

while 1:

   value="1"
   ser.write(value.encode())
   Data = ser.readline()
   x = ((Data))

f= (x[1:5])
f = x.decode()

The solution is to execute the infinite loop in a thread and send the information through signals.

import threading
import time

from PyQt5.QtCore import pyqtSignal, QObject


class SerialManager(QObject):
    value_changed = pyqtSignal(str)

    def start(self):
        threading.Thread(target=self.run, daemon=True).start()

    def run(self):
        ser= serial.Serial(port="com4", baudrate=115200, timeout=1)
        while ser.is_open:
            value="1"
            ser.write(value.encode())
            data = ser.readline()
            f = data[1:5].decode()
            self.value_changed.emit(f)
            time.sleep(.1)
class AppDemo(QWidget):
    def __init__(self):
        super().__init__()
        uic.loadUi('app.ui', self)
        self.serial_manager = SerialManager()
        self.serial_manager.value_changed.connect(self.Motor_Speed_Lcd.display)
        self.serial_manager.start()