I am trying to force the user to fill the QPlainTextEdit, and then click the button. Further, I wanna prevent the user to click outside the QMainWindow and avoid filling the text. In essence, the user is forced to enter the text and click the button.
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.window.setWindowFlag(Qt.WindowStaysOnTopHint)
self.label = QLabel()
self.label.setText("Write Something.")
self.label.setAlignment(Qt.AlignCenter)
self.text_area = QPlainTextEdit(self)
self.button = QPushButton("Save",self)
self.button.setDisabled(True)
self.text_area.textChanged.connect(self.enable_button)
self.button.clicked.connect(self.store_message)
self.vbox = QVBoxLayout()
self.vbox.addWidget(self.label)
self.vbox.addStretch()
self.vbox.addWidget(self.text_area)
self.vbox.addWidget(self.button)
# self.vbox.addStretch()
self.window.setLayout(self.vbox)
self.window.show()
def enable_button(self):
if self.text_area.toPlainText() != "":
self.button.setEnabled(True)
else:
self.button.setDisabled(True)
def store_message(self):
## do something
print("Saving..")
Thanks in advance.