我正在使用pyqt5创建一个GUI并使用qlcdnumber来显示一个变量,我通过套接字服务器从Android应用程序中检索该变量。 问题是我找不到任何方法来显示我在qlcdnumber中的变量。
这是UI代码,我试图使用信号但没有用。
class MyTCPHandler(socketserver.StreamRequestHandler):
def handle(self):
while True:
global angle, strength ,speed, a
if(not enabled):
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
self.data = self.rfile.readline().strip()
if(a==0):
print("{} wrote:".format(self.client_address[0]))
a+=1
data = self.data.decode("utf-8").rstrip().strip("\n")
if(data!= ""):
if(data == "disconnect"):
print("restarting")
self.close()
sleep(1)
mainServer()
elif(data == "shutdown"):
p = subprocess.Popen("sudo shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(p)
else:
temp = data.split(":")
angle = int(temp[0])
strength = int(temp[1])
speed = float(temp[2])
class Ui_AppWindow(QtWidgets.QWidget):
def __init__(self):
super(Ui_AppWindow, self).__init__()
self.setStyleSheet('background-color:#efefef; color:white;')
global add, angle, speed
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel("\t\t"+add)
self.label.setStyleSheet("color: #005C99;")
self.layout.addWidget(self.label)
palette = QtGui.QPalette()
palette.setColor(palette.WindowText, QtGui.QColor(85, 85, 255))
palette.setColor(palette.Background, QtGui.QColor(0, 170, 255))
palette.setColor(palette.Light, QtGui.QColor(0, 92, 153))
palette.setColor(palette.Dark, QtGui.QColor(0, 92, 137))
self.speed = QtWidgets.QLCDNumber(self)
self.speed.setGeometry(QtCore.QRect(100, 100, 64, 23))
self.speed.setObjectName("speed")
self.speed.display(speed)
self.speed.setPalette(palette)
self.angle = QtWidgets.QLCDNumber(self)
self.angle.setGeometry(QtCore.QRect(200, 100, 64, 23))
self.angle.setObjectName("angle")
self.angle.display(angle)
self.angle.setPalette(palette)
self.speed_lable = QtWidgets.QLabel("Speed")
self.speed_lable.setGeometry(QtCore.QRect(100, 70, 47, 25))
self.speed_lable.setObjectName("speed_lable")
self.speed_lable.setStyleSheet('color:#00497a;')
self.angle_lable = QtWidgets.QLabel("Angle")
self.angle_lable.setGeometry(QtCore.QRect(200, 70, 47, 25))
self.angle_lable.setObjectName("angle_lable")
self.angle_lable.setStyleSheet('color:#00497a;')
self.hbl = QtWidgets.QHBoxLayout()
self.hbl.addWidget(self.speed_lable)
self.hbl.addWidget(self.angle_lable)
self.layout.addLayout(self.hbl)
self.hb = QtWidgets.QHBoxLayout()
self.hb.addWidget(self.speed)
self.hb.addWidget(self.angle)
self.layout.addLayout(self.hb)
self.setWindowTitle("RasControl GUI: Android Control")
self.setLayout(self.layout)
self.setGeometry(100, 100, 400, 200)
def setAngle(self):
global angle
self.angle.display(angle)
def setSpeed(self):
global speed
self.speed.display(speed)
我想要设置的变量显示在qlcdnumber;
global speed, angle
server = socketserver.TCPServer((ip, port), MyTCPHandler)
server.serve_forever()
并在主GUI中调用Ui_AppWindow gui,但我需要每次更改时使用全局变量速度和角度的值更新qlcdnumber。
答案 0 :(得分:0)
最简单的方法就是创建总是用来设置程序中全局变量值的函数,如下所示:
<?php
// composer require zendframework/zend-soap
require_once __DIR__ . '/vendor/autoload.php';
$client = new Zend\Soap\Client("http://demo.coveto.de/soap?wsdl");
$result1 = $client->getFunctions();
var_dump($result1);