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())
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。