Python Forum

Full Version: help code python QT Designer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have created an interface with buttons and comboBoxes and I want to change the value of DATA [1] which is in the send.py file every time I press a button, it assigns it the new value of DAT1.

I have defined the functions of BTN1, BTN2, BTN3 for the push buttons

I want to have an idea how to code to have the desired result

[Image: 5e53d067-2c0a-45e9-b68c-662d69d0313c.png]



here is the code of my 2 file Python


# -*- coding: utf-8 -*-


from PyQt5 import QtCore, QtGui, QtWidgets
from send import *

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(975, 603)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(130, 110, 91, 21))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Form)
        self.pushButton_2.setGeometry(QtCore.QRect(130, 170, 93, 21))
        self.pushButton_2.setObjectName("pushButton_2")
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setGeometry(QtCore.QRect(30, 110, 73, 22))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox_2 = QtWidgets.QComboBox(Form)
        self.comboBox_2.setGeometry(QtCore.QRect(30, 170, 73, 22))
        self.comboBox_2.setObjectName("comboBox_2")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.pushButton_3 = QtWidgets.QPushButton(Form)
        self.pushButton_3.setGeometry(QtCore.QRect(130, 230, 93, 21))
        self.pushButton_3.setObjectName("pushButton_3")
        self.comboBox_3 = QtWidgets.QComboBox(Form)
        self.comboBox_3.setGeometry(QtCore.QRect(30, 230, 73, 22))
        self.comboBox_3.setObjectName("comboBox_3")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
        
        self.pushButton.clicked.connect(self.BTN1)
        self.pushButton_2.clicked.connect(self.BTN2)
        self.pushButton_3.clicked.connect(self.BTN3)

        
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)



    def BTN1(self,DAT1):

        x=int(self.comboBox.currentText())
 
        if x == 1:

            a= 0b00000111 or DAT1
            DAT1 = a
 
            print("Communication BTN1 Detected")
            return DAT1
        elif x == 0:

            b= 0b11111000 and DAT1
            DAT1 = b

            print("Communication BTN1 NOT Detected")

            return DAT1
        
    def BTN2(self,DAT1):

        x=int(self.comboBox_2.currentText())
 
        if x == 1:

            a= 0b00111000 or DAT1
            DAT1 = a
            
                
                
            print("Communication BTN2 Detected")
            return DAT1
        elif x == 0:


            b= 0b11000111 and DAT1
            DAT1 = b

            print("Communication BTN2 NOT Detected")

            return DAT1

    def BTN3(self,DAT1):
        x=int(self.comboBox_3.currentText())
 
        if x == 1:

            a= 0b11000000 or DAT1
            DAT1 = a
       
            print("Communication BTN3 Detected")
            return DAT1
        elif x == 0:


            b= 0b00111111 and DATA1
            DATA1 = b

            print("Communication BTN3 NOT Detected")

            return DAT1

 
    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "BTN1"))
        self.pushButton_2.setText(_translate("Form", "BTN2"))
        self.comboBox.setItemText(0, _translate("Form", "1"))
        self.comboBox.setItemText(1, _translate("Form", "0"))
        self.comboBox_2.setItemText(0, _translate("Form", "1"))
        self.comboBox_2.setItemText(1, _translate("Form", "0"))
        self.pushButton_3.setText(_translate("Form", "BTN3"))
        self.comboBox_3.setItemText(0, _translate("Form", "1"))
        self.comboBox_3.setItemText(1, _translate("Form", "0"))
       


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
####################################################################
from PCANBasic import *
from exemple import *


DAT1=0b11111111


#Initialize the PCAN

m_PCAN = PCANBasic()

m_Result = m_PCAN.Initialize(PCAN_USBBUS1, PCAN_BAUD_500K)


# Send DATA of ARD1

#####################################ARD1#####################
ARD1 = TPCANMsg()

ARD1.ID = 0x461
ARD1.LEN =8
ARD1.DATA[0] = 0x07
ARD1.DATA[1] = DAT1


print(ARD1.DATA[1])


ARD1.MSGTYPE = PCAN_MESSAGE_STANDARD

m_Result = m_PCAN.Write(PCAN_USBBUS1,ARD1)

if m_Result == PCAN_ERROR_OK :
        print("ARD1 Send")
else:
    print("ARD1 Not Send")

m_PCAN.Uninitialize(PCAN_USBBUS1)