相關(guān)推薦
您可能對(duì)下面課程感興趣
Python上位機(jī)開發(fā)教程

99小節(jié)已有4502人學(xué)過

Python上位機(jī)開發(fā)布局嵌套
發(fā)布時(shí)間:2024-11-20 10:01 [ 我要自學(xué)網(wǎng)原創(chuàng) ] 發(fā)布人: 快樂小女 閱讀: 53

from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(300,400)
        self.setWindowTitle("S7通信測(cè)試")

        main_layout = QVBoxLayout()
        main_layout.addWidget(self.group_connect_plc())
        main_layout.addWidget(self.group_read_write_plc())

        self.setLayout(main_layout)

    def group_connect_plc(self):
        group = QGroupBox("連接PLC")
        le_plc_addr = QLineEdit()
        le_plc_rack = QLineEdit()
        le_plc_slot = QLineEdit()
        btn_connect = QPushButton("連接")
        btn_disconnect = QPushButton("斷開連接")

        #創(chuàng)建表單布局
        form_layout  = QFormLayout()
        form_layout.addRow("PLC Adress:",le_plc_addr)
        form_layout.addRow("PLC Rack:",le_plc_rack)
        form_layout.addRow("PLC Slot:",le_plc_slot)
        form_layout.addRow(btn_connect,btn_disconnect)
        form_layout.setSpacing(20)
        form_layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.FieldsStayAtSizeHint)

        #父對(duì)象設(shè)置布局器
        group.setLayout(form_layout)
        return group

    def group_read_write_plc(self):
        group = QGroupBox("讀寫數(shù)據(jù)")
        label_db_num = QLabel("DB Number")
        le_db_num = QLineEdit()
        label_start_addr = QLabel("Start Adress")
        le_start_addr = QLineEdit()
        label_data_type = QLabel("Data Type")
        combox = QComboBox()
        label_value_to_write = QLabel("Value to Write")
        le_value_to_write = QLineEdit()
        btn_read = QPushButton("read")
        btn_write= QPushButton("write")

        grid_layout = QGridLayout()
        grid_layout.addWidget(label_db_num,0,0)
        grid_layout.addWidget(le_db_num,0,1)
        grid_layout.addWidget(label_start_addr,1,0)
        grid_layout.addWidget(le_start_addr,1,1)
        grid_layout.addWidget(label_data_type,2,0)
        grid_layout.addWidget(combox,2,1)
        grid_layout.addWidget(label_value_to_write,3,0)
        grid_layout.addWidget(le_value_to_write,3,1)
        grid_layout.addWidget(btn_read,2,2)
        grid_layout.addWidget(btn_write,3,2)

        group.setLayout(grid_layout)

        return group


if __name__ == '__main__':
    def btn_slot(a,b,c):
        print(a,b,c)


    import sys
    app = QApplication(sys.argv)
    win = Window()
    win.plc_signal_data.connect(btn_slot)
    win.show()
    sys.exit(app.exec())

文章評(píng)論
0 條評(píng)論 按熱度排序 按時(shí)間排序 /350
添加表情
遵守中華人民共和國(guó)的各項(xiàng)道德法規(guī),
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。
V
特惠充值
聯(lián)系客服
APP下載
官方微信
返回頂部
相關(guān)推薦
您可能對(duì)下面課程感興趣
Python上位機(jī)開發(fā)教程

99小節(jié)已有4502人學(xué)過

分類選擇:
電腦辦公 平面設(shè)計(jì) 室內(nèi)設(shè)計(jì) 室外設(shè)計(jì) 機(jī)械設(shè)計(jì) 工業(yè)自動(dòng)化 影視動(dòng)畫 程序開發(fā) 網(wǎng)頁(yè)設(shè)計(jì) 會(huì)計(jì)課程 興趣成長(zhǎng) AIGC