我正在尝试将Qspinboxs用作某些功能的设定点。但是我不能将这些变量传递给另一个函数。
试图使用全局变量没有成功。这是一个代码示例。
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow,QLabel,
QDoubleSpinBox,QFileDialog, QApplication, QTableWidget, QPushButton,
QMessageBox, QGridLayout, QWidget
import pandas as pd
import numpy as np
data = np.arange(1,100,2)
df = pd.DataFrame(data=data, columns=['M'])
M = df['M']
print (M)
类窗口(QtWidgets.QWidget):
def __init__(self):
super(Window, self).__init__()
self.initUi()
def initUi(self):
self.setWindowTitle("Cut-off points")
self.setGeometry(200, 100, 530, 350)
self.label = QLabel("A", self)
self.label.setGeometry(230, 20, 200, 100)
self.label.setStyleSheet("QLabel{font-size: 30px;setFontItalic;font-
family: TimeNewRoman;"
"color: #7f2e0b;}")
self.labe2 = QLabel("B", self)
self.labe2.setGeometry(330, 20, 200, 100)
self.labe2.setStyleSheet("QLabel{font-size: 30px;setFontItalic;font-
family: TimeNewRoman;"
"color: #7f2e0b;}")
self.labe3 = QLabel("C", self)
self.labe3.setGeometry(430, 20, 200, 100)
self.labe3.setStyleSheet("QLabel{font-size: 30px;setFontItalic;font-
family: TimeNewRoman;"
"color: #7f2e0b;}")
self.SpinBox1=QDoubleSpinBox(self)
self.SpinBox1.setGeometry(230, 90, 70, 30)
self.SpinBox1.setValue(0.1)
self.SpinBox1.valueChanged.connect(self.Rok)
self.SpinBox2 = QDoubleSpinBox(self)
self.SpinBox2.setGeometry(330, 90, 70, 30)
self.SpinBox2.setValue(0.5)
self.SpinBox2.valueChanged.connect(self.Rok)
self.SpinBox3 = QDoubleSpinBox(self)
self.SpinBox3.setGeometry(430, 90, 70, 30)
self.SpinBox3.setValue(0.3)
self.SpinBox3.valueChanged.connect(self.Rok)
self.label2 = QLabel("Rock", self)
self.label2.setGeometry(30, 50, 200, 100)
self.label2.setStyleSheet("QLabel{font-size: 40px;setFontItalic;font-
family: TimeNewRoman;"
"color: #7f2e0b;}")
self.label3 = QLabel("Rock1", self)
self.label3.setGeometry(30, 100, 200, 100)
self.label3.setStyleSheet("QLabel{font-size: 40px;setFontItalic;font-
family: TimeNewRoman;"
"color: #7f2e0b;}")
self.label4 = QLabel("Rock2", self)
self.label4.setGeometry(30, 150, 200, 100)
self.label4.setStyleSheet("QLabel{font-size: 40px;setFontItalic;font-family: TimeNewRoman;"
"color: #7f2e0b;}")
button_11 = QPushButton("Ok", self)
button_11.setGeometry(200, 270, 100, 60)
button_11.setStyleSheet("QPushButton{font-size: 30px;font-family: TimeNewRoman;"
"color: rgb(255, 255, 255);background-color: #f413e5;}")
button_11.clicked.connect(self.CloseAPP)
self.show()
def Rok(self, x):
global A, B, C
A = float(self.SpinBox1.value())
B = float(self.SpinBox2.value())
C = float(self.SpinBox3.value())
return A, B, C
def Rock(x):
if x['M'] < A:
return 1
return 0
df['sm']= df.apply(Rock, axis=1)
def CloseAPP(self):
reply = QMessageBox.question(self,"close","are you sure",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.Yes:
self.close()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec()
我希望使用if,else条件(根据从旋转框获得的设置点)获得某些列的数据框。