Python Forum
[PyGUI] help code python QT Designer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] help code python QT Designer
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QT Designer Krissstian 4 1,639 May-26-2022, 09:45 AM
Last Post: Krissstian
  Qt Designer : help document viewer error. davediamond 2 1,540 Apr-14-2022, 10:38 AM
Last Post: davediamond
  GUI programming PyQt 5 + Qt Designer flash77 9 2,639 Mar-19-2022, 10:31 AM
Last Post: flash77
  [PyQt] QT5 Designer Drawing greenhorn1 1 2,511 Dec-30-2021, 05:12 PM
Last Post: deanhystad
  Installed Designer - Helpf Files for "assistant" are missing Valmont 0 1,987 Mar-22-2021, 11:09 AM
Last Post: Valmont
  Using a GUI Designer vs. hard coding 357mag 9 5,961 Feb-21-2021, 06:43 PM
Last Post: kkaur
  Attempting to use Qt Designer. thewolf 17 5,977 Feb-17-2021, 12:03 AM
Last Post: thewolf
  [Kivy] Kivy Designer Module Error SARAVANAN_M 0 3,835 Nov-20-2019, 09:57 AM
Last Post: SARAVANAN_M
  [PyQt] Send data between windows Pyqt5 and Qt Designer kkonrad002 8 10,040 Sep-05-2019, 02:25 PM
Last Post: Denni
  [PyQt] Qt Designer - Making a Font with a border jimmyvegas29 4 7,453 Feb-19-2019, 11:08 PM
Last Post: jimmyvegas29

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020