Подскажите,пожалуйста,как мне получить данные из ячеек и внести в каждую ячейку 5 столбца комбобокс .
Затем нужно использовать значение этих ячеек. Как связать значение комбобокса с переменной?
import numpy as np import xlwt import sys from matplotlib import pylab as plt from PyQt5.QtWidgets import QApplication, QPushButton,QTableWidget, QSpinBox,QMessageBox from PyQt5.QtCore import Qt from PyQt5 import QtWidgets from PyQt5.QtWidgets import QWidget, QComboBox class mw(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.spin = QSpinBox(self) self.spin.move(10, 10) self.spin.setMaximum(100) self.spin.setMinimum(1) self.spin.valueChanged.connect(self.change) self.table = QTableWidget(self) self.table.resizeColumnsToContents() self.table.setColumnCount(6) self.table.setRowCount(int(self.spin.text())) self.table.setHorizontalHeaderLabels(["Диаметр л, мм","Диаметр о, мм","Разрушающая нагрузка, КН", "Высота, мм", "Ширина , мм","Форма "]) self.table.move(10, 50) self.table.horizontalHeaderItem(0).setTextAlignment(Qt.AlignHCenter) self.table.horizontalHeaderItem(1).setTextAlignment(Qt.AlignHCenter) self.table.horizontalHeaderItem(2).setTextAlignment(Qt.AlignHCenter) self.table.horizontalHeaderItem(4).setTextAlignment(Qt.AlignHCenter) self.table.horizontalHeaderItem(5).setTextAlignment(Qt.AlignHCenter) self.table.resize(1039, 100) self.table.resizeColumnsToContents() u= int(self.spin.text()) m =1 while m <= u: self.table.setItem(m, 5, QtWidgets.QTableWidgetItem(m)) self.combo = QComboBox(self.table) self.comboBox = QtWidgets.QComboBox() self.table.setCellWidget(m,5, self.combo) self.combo.addItem(str(1)) self.combo.addItem(str(np.pi / 4)) m = m + 1 # Делаем кнопку, по нажатию которой мы должны передаём данные дальше в обработку self.btn = QPushButton("OK", self) self.btn.move(80, 10) self.btn.resize(30, 30) self.btn.clicked.connect(self.get_data) self.setGeometry(0, 0, 1360, 1080) self.setWindowTitle("Application") self.show() def change(self): self.table.setRowCount(int(self.spin.text())) u = int(self.spin.text()) def get_data(self): Sit = 0 Pv = 0 Si3s=0 Ki = 0 TanFi0 = 0 Fi0 =0 C0i = 0 TanFi =0 Fi = 0 Ci = 0 Sis = 0 Sivs =0 Khr = 0 for i in range(self.table.rowCount()): dlunk=float(self.table.item(i, 0).text()) dot=float(self.table.item(i, 1).text()) Pkgs=float(self.table.item(i, 2).text()) a=float(self.table.item(i, 3).text()) b=float(self.table.item(i, 4).text()) N=float(self.table.item(i, 5).text()) if a <= 0 or b <= 0 or dot <= 0 or dlunk <= 0 or Pkgs <= 0: QMessageBox.about(ex, "Ошибка", "Вводимые данные должны быть больше нуля") else: S = a * b * N / 100 F = np.pi * dlunk * dot / 100 Sit = float(Pkgs / (10 * S)) Pv = Pkgs / (10 * F) TanFi0 = 0.5 * (Pv - Sit) / np.sqrt(Sit * Pv) Fi0 = np.arctan(TanFi0) * 180 / np.pi C0i = np.sqrt(Sit * Pv) TanFi = (np.sqrt(Pv) - np.sqrt(Sit)) * 0.5 / (np.sqrt(np.sqrt(Pv * Sit))) Fi = np.arctan(TanFi) * 180 / np.pi Ci = np.sqrt(np.sqrt(Pv * Sit)) * (np.sqrt(Pv) + np.sqrt(Sit)) * 0.5 Sis = Pv + np.sqrt(Sit * Pv) Sivs = 2 * Pkgs / (10 * (S + F)) Khr = Sis / Sivs Si3s = 2 * Pkgs if Khr < 5: sheet1.write(i, 17, "Значение не определить, т.к показатель меньше 5") if Khr > 5: KPuass = 1.4 / (Khr - 2.05) sheet1.write(i, 17, KPuass) Ki = Pv / Sit Sit = Sit + Sit Pv = Pv + Pv Si3s = Si3s+Si3s Ki = Ki + Ki TanFi0 = TanFi0 + TanFi0 Fi0 = Fi0 + Fi0 C0i = C0i + C0i TanFi = TanFi + TanFi Fi = Fi + Fi Ci = Ci + Ci Sis = Sis + Sis Sivs = Sivs + Sivs Khr = Khr + Khr Sit = Sit/i Pv = Pv/i Si3s=Si3s/i Ki = Ki / i TanFi0 = TanFi0 / i Fi0 = Fi0 / i C0i = C0i / i TanFi = TanFi / i Fi = Fi / i Ci = Ci / i Sis = Sis / i Sivs = Sivs / i Khr = Khr / i Xc1 = (-1) * Sit R1 = Sit Xc2 = 0 R2 = Sit * Pv * 2 / (Sit + Pv) Xc3 = (Pv - Sit) / 2 R3 = (Pv - Sit) / 2 Xc4 = (Pv + C0i) / 2 R4 = (Pv + C0i) / 2 Xc5 = (Pv + 2 * C0i + Sit) / 2 R5 = (Pv + 2 * C0i - Sit) / 2 Xc6 = Pv + C0i R6 = Pv Xc7 = (Pv + C0i) * (2 + np.sqrt(Pv / Sit)) / 2 R7 = (Pv + C0i) * np.sqrt(Pv / Sit) / 2 Xc8 = (Pv + C0i) * (Pv / Sit + np.sqrt(Pv / Sit) - 2) / 4 R8 = 3 * C0i / 2 + ((Pv - 3 * Sit) * Pv / Sit) / 4 Xc9 = (Pv + Sit) / 2 R9 = Sit + Pv / 2 def Mrc(x, r, x0): g = r * r - (x - x0) * (x - x0) y = np.sqrt(g) return y def Linep(g, g1, g2, v1, v2): v = g * (v2 - v1) / (g2 - g1) - g1 * (v2 - v1) / (g2 - g1) + v1 return v X_l1 = np.linspace(Xc1 - R1, Xc1 + R1, 1000) # графика кругов 1-8 Y1 = Mrc(X_l1, R1, Xc1) X_l2 = np.linspace(Xc2 - R2, Xc2 + R2, 100000) Y2 = Mrc(X_l2, R2, Xc2) X_l3 = np.linspace(Xc3 - R3, Xc3 + R3, 100000) Y3 = Mrc(X_l3, R3, Xc3) X_l4 = np.linspace(Xc4 - R4, Xc4 + R4, 100000) Y4 = Mrc(X_l4, R4, Xc4) X_l5 = np.linspace(Xc5 - R5, Xc5 + R5, 100000) Y5 = Mrc(X_l5, R5, Xc5) X_l8 = np.linspace(Xc8 - R8, Xc8 + R8, 100000) Y8 = Mrc(X_l8, R8, Xc8) X_l6 = np.linspace(Xc6 - R6, Xc6 + R6, 100000) Y6 = Mrc(X_l6, R6, Xc6) X_l9 = np.linspace(Xc9 - R9, Xc9 + R9, 100000) Y9 = Mrc(X_l9, R9, Xc9) X_l7 = np.linspace(Xc7 - R7, Xc7 + R7, 100000) Y7 = Mrc(X_l7, R7, Xc7) # конец кругов X_l9 = np.linspace(Xc9 - R9, Xc9 + R9, 100000) Y9 = Mrc(X_l9, R9, Xc9) if R6 > R8: Rmaxi = R6 Xmaxi = Xc6 else: Rmaxi = R8 Xmaxi = Xc8 YTau077 = 0.73 * Rmaxi XTau077 = Xmaxi - np.sqrt(Rmaxi * Rmaxi - YTau077 * YTau077) Lx1 = np.linspace((-2) * Sit, 0, 1000) # TAU1 = Linep(Lx1, 0, (-2) * Sit, Ci, 0) XLd = np.linspace(XTau077, Xmaxi, 1000) YLd = Mrc(XLd, Rmaxi, Xmaxi) Lx2 = np.linspace(0, XTau077, 1000) # TAU2 = Linep(Lx2, XTau077, 0, YTau077, Ci) Lmax = np.linspace(Xmaxi, 1.12 * Rmaxi + Xmaxi, 1000) TAUmax = Rmaxi + Lmax * 0 plt.plot(X_l1, Y1, 'blue', X_l2, Y2, 'blue', X_l3, Y3, 'blue', X_l4, Y4, 'blue', X_l5, Y5, 'blue', X_l6, Y6, 'blue', X_l7, Y7, 'blue', X_l8, Y8, 'blue') plt.plot(X_l9, Y9, 'blue', label='Круги Мора') plt.plot(Lx1, TAU1, 'red', Lx2, TAU2, 'red', XLd, YLd, 'r') plt.plot(Lmax, TAUmax, 'r', label='Огибающая') plt.legend() plt.xlabel(chr(963) + ", МПа") plt.ylabel(chr(964) + ", МПа") plt.axis('scaled') plt.ylim(0, ) plt.title("Паспорт прочности образца горной породы ") plt.grid() plt.show() Sic = Pv + C0i SiT = 2 * Sit * Pv / (Sit + Pv) Si3 = np.sqrt(Ki) * (Sic / 2 - 2 * Sit) Si1 = Sic + Ki * (Sic / 2 - 2 * Sit) Sib3 = Sit * (Si1 - Sit) / (Ki * (Si3 + Sit) - (Si1 - Sit)) Sib1 = ((Si1 - Sit) * Sib3 + Sit * (Si1 + Si3)) / (Si3 + Sit) FDx1 = np.linspace(-1 * SiT, (-1) * Sit, 1000) # графика кривой FD = Linep(FDx1, -1 * SiT, (-1) * Sit, Sit, Pv) DEx = np.linspace((-1) * Sit, Si3, 1000) # графика кривой DE = Linep(DEx, (-1) * Sit, Si3, Pv, Si1) ABx1 = np.linspace(0, Sib3, 1000) # графика кривой AB = Linep(ABx1, 0, Sib3, Sit, Sib1) BEx = np.linspace(Sib3, Si3, 1000) # графика кривой BE = Linep(BEx, Sib3, Si3, Sib1, Si1) Ch = np.linspace(-1 * Sit, Sib3) Cy = Linep(Ch, -1 * Sit, Sib3, Sit, Sib1) plt.plot(FDx1, FD, 'r') plt.plot(DEx, DE, 'r', label='') plt.plot(ABx1, AB, 'k', ) plt.plot(BEx, BE, 'k', label='') plt.plot(Ch, Cy, 'blue', label='') plt.legend() plt.xlabel(chr(963) + "3") plt.ylabel(chr(963) + "3") plt.ylim(0, ) plt.ylim(0, ) plt.grid() plt.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = mw() sys.exit(app.exec_())