How do I get and store the value that is written in a QLineEdit as well as close the widget after I click save? I have looked over the PyQt5 documentation and it says the function .text() will give access to the values in a QLineEdit but for some reason the value I keep getting is the default empty string. Any help in finding out what I am missing is appreciated. Thanks
class ImageSettingsWindow(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout() self.setWindowTitle("Image Settings") self.setFixedWidth(250) self.setFixedHeight(300) allImg_checkBox = QCheckBox("All Images") lastImg_checkBox = QCheckBox("Last Image") timedImgs_checkBox = QCheckBox("Timed Images") start_label = QLabel("Start Duration:") txt_start = QLineEdit() self.data_start = txt_start.ui.text() end_label = QLabel("End Duration:") txt_end = QLineEdit() self.data_end = txt_end.ui.text() timeInt_label = QLabel("Time Interval:") txt_timeInt = QLineEdit() self.data_timeint = txt_timeInt.ui.text() maxDiff_label = QLabel("Max Difference:") txt_maxDiff = QLineEdit() self.data_maxdiff = txt_maxDiff.ui.txt() buttonSave = QPushButton("Save") layout.addWidget(allImg_checkBox) layout.addWidget(lastImg_checkBox) layout.addWidget(timedImgs_checkBox) layout.addWidget(start_label) layout.addWidget(txt_start) layout.addWidget(end_label) layout.addWidget(txt_end) layout.addWidget(timeInt_label) layout.addWidget(txt_timeInt) layout.addWidget(maxDiff_label) layout.addWidget(txt_maxDiff) layout.addWidget(buttonSave) print(self.data_start) self.setLayout(layout) buttonSave.clicked.connect(self.clickedSave) def clickedSave(self): #data_start = self. print("button") try: json_image = open("config/image.json","r") param = json.load(json_image) json_image.close() param["start_duration"] = int(self.data_start) param["end_duration"] = int(self.data_end) param["time_interval"] = float(self.data_timeint) param["max_diff"] = int(self.data_maxdiff) json_image = open("config/image.json", "w") json.dump(param,json_image) json_image.close() except IOError as err : print("Error writing the image.json file , please double check")
https://stackoverflow.com/questions/65802112/how-do-i-access-the-value-from-a-qlineedit-in-pyqt5 January 20, 2021 at 10:07AM
没有评论:
发表评论