我有一个简单的Pyside窗口/ gui,我只想通过函数调用给定“ rgb”代码的颜色背景来进行更改。这是我的最终目标。
据我了解,我应该在窗口中设置一个与外部发送方进行通信的接收方。
我在第13行出现以下错误:
self.receiver = self.Receiver.on_receiver() TypeError:on_receiver()缺少2个必需的位置参数:“ self”和“ l”
import sys, time ,PySide2
from PySide2.QtWidgets import QWidget
class LED_sim(QWidget):
app = PySide2.QtWidgets.QApplication(sys.argv)
def __init__(self):
super().__init__()
self.setWindowTitle('Virtual LED')
self.coloring() # Call for coloring window
self.receiver = self.Receiver().on_receiver
def coloring(self):
self.setStyleSheet("background-color: rgb(0,230,0);")
self.show() # Show the window
class Receiver(PySide2.QtCore.QObject):
@PySide2.QtCore.Slot(list)
def on_receiver(self, l):
print(l)
PySide2.QtCore.QCoreApplication.quit()
class Sender(PySide2.QtCore.QObject):
signal = PySide2.QtCore.Signal(list)
def on_test(self):
l = [["r", "g", "b", ] ]
self.signal.emit(l)
if __name__=="__main__":
LED = LED_sim()
SENDER= Sender()
SENDER.signal.connect(LED.Receiver.on_receiver())
QtCore.QTimer.singleShot(1000, SENDER.on_test)
sys.exit(LED_sim.app.exec_()) # Ensure the execution
该代码的预期输出应在端子[“ r”,“ g”,“ b”,]中。
我的最终目标是模拟每3秒钟显示给定“ rgb”颜色的灯。
此代码是中间步骤。