使用pyqt5中的另一个按钮激活按钮,我应该使用if语句吗?

问题描述 投票:0回答:1

这是怎么回事...

我想按SD底部,这将激活四个测试点向下并为其分配以下IP地址,因此,当我按TP1时,它将使用TP1地址,依此类推。

我正在尝试使用if函数,但无法正常运行!!有没有更好的方法呢?

代码:

from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication,
                             QGridLayout, QLCDNumber)
from PyQt5 import QtCore, QtGui, QtWidgets
from QLed import QLed

class MainProg(QtWidgets.QMainWindow):

    def __init__(self):


        super(MainProg, self).__init__()


        self.setObjectName("MainWindow")

        self.setFixedSize(1366, 768)

        self.AASD = QtWidgets.QToolButton(self)
        self.AASD.setGeometry(QtCore.QRect(140, 70, 31, 32))
        self.AASD.clicked.connect(self.ASD)

        self.AAHD = QtWidgets.QToolButton(self)
        self.AAHD.setGeometry(QtCore.QRect(180, 70, 31, 32))
        #self.AASD.clicked.connect(self.AHD)


        self.AASD.setText("SD")
        self.AAHD.setText("HD")


        ##################################################3
        self.Testpunk1 = QtWidgets.QToolButton(self)
        self.Testpunk1.setGeometry(QtCore.QRect(150, 460, 31, 32))

        self.Testpunk2 = QtWidgets.QToolButton(self)
        self.Testpunk2.setGeometry(QtCore.QRect(150, 510, 31, 32))

        self.Testpunk3 = QtWidgets.QToolButton(self)
        self.Testpunk3.setGeometry(QtCore.QRect(150, 595, 31, 32))
        self.Testpunk4 = QtWidgets.QToolButton(self)
        self.Testpunk4.setGeometry(QtCore.QRect(150, 650, 31, 32))

        self.Testpunk5 = QtWidgets.QToolButton(self)
        self.Testpunk5.setGeometry(QtCore.QRect(710, 465, 31, 32))
        self.Testpunk6 = QtWidgets.QToolButton(self)
        self.Testpunk6.setGeometry(QtCore.QRect(710, 515, 31, 32))

        self.Testpunk7 = QtWidgets.QToolButton(self)
        self.Testpunk7.setGeometry(QtCore.QRect(710, 600, 31, 32))
        self.Testpunk8 = QtWidgets.QToolButton(self)
        self.Testpunk8.setGeometry(QtCore.QRect(710, 650, 31, 32))
        self.Testpunk1.setText("TP1")
        self.Testpunk2.setText("TP2")
        self.Testpunk3.setText("TP3")
        self.Testpunk4.setText("TP4")

        self.Testpunk5.setText("TP5")
        self.Testpunk6.setText("TP6")
        self.Testpunk7.setText("TP7")
        self.Testpunk8.setText("TP8")



        ###################the LEDs####################

        self.Tp1 = QLed(self, onColour=QLed.Orange, shape=QLed.Circle)
        self.Tp1.setGeometry(QtCore.QRect(185, 465, 25, 25))
        self.Tp1.value = False

        self.Tp2 = QLed(self, onColour=QLed.Orange, shape=QLed.Circle)
        self.Tp2.setGeometry(QtCore.QRect(185, 600, 25, 25))
        self.Tp2.value = False

        self.Tp3 = QLed(self, onColour=QLed.Orange, shape=QLed.Circle)
        self.Tp3.setGeometry(QtCore.QRect(745, 470, 25, 25))
        self.Tp3.value = False

        self.Tp4 = QLed(self, onColour=QLed.Orange, shape=QLed.Circle)
        self.Tp4.setGeometry(QtCore.QRect(745, 605, 25, 25))
        self.Tp4.value = False

    def TPLed(self):

        self.Tp1.value = True  # the LED ON code
        self.Tp3.value = True  # the LED ON code
        self.Tp2.value = True  # the LED ON code
        self.Tp4.value = True


    def ASD(self):


        self.TPLed()
        TP1 = "239.168.1.6:1112"
        TP2 = "239.168.1.7:1116"
        TP3 = "239.168.1.6:1132"
        TP4 = "239.168.1.6:1136"
        TP5 = "239.168.2.6:2113"
        TP6 = "239.168.2.7:2122"
        TP7 = "239.168.2.8:2132"
        TP8 = "239.168.2.9:2142"


        if  self.Testpunk1.click():
            myurl = TP1
            print("TP1 is playing")
            pass
        if self.Testpunk2.click():
            myurl = TP2
            print("TP2 is playing")
            pass
        if self.Testpunk3.click():
            myurl = TP3
            print("TP3 is playing")
            pass
        if self.Testpunk4.click():
            myurl = TP4
            print("TP4 is playing")
            pass
        if self.Testpunk5.click():
            myurl = TP5
            print("TP5 is playing")
            pass
        if self.Testpunk6.click():
            myurl = TP6
            print("TP6 is playing")
            pass
        if self.Testpunk7.click():
            myurl = TP7
            print("TP7 is playing")
            pass

        if self.Testpunk8.click():
            myurl = TP8
            print("TP8 is playing")
            pass

    def AADH(self):
        #the same with different IP addresses
        pass




if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    player = MainProg()
    player.show()
    sys.exit(app.exec_())
python pyqt pyqt5
1个回答
0
投票

我不知道您到底想做什么,但是答案就在这里。

© www.soinside.com 2019 - 2024. All rights reserved.