Hi
This is my very (very) first test to code a GUI and I know it'll be a very (very) long way
.
In the following example, printing textbox content works, but I do not figured out how to record it into a variable; I'm persuaded I'm missed many things and I'm lost in the huge documentations: links and advices are highly apprciated.
Paul
This is my very (very) first test to code a GUI and I know it'll be a very (very) long way
.In the following example, printing textbox content works, but I do not figured out how to record it into a variable; I'm persuaded I'm missed many things and I'm lost in the huge documentations: links and advices are highly apprciated.
Paul
import sys
from PySide6.QtWidgets import QMainWindow, QApplication, QWidget, QLineEdit
from PySide6.QtCore import Slot
class MyMainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Qt window")
self.setMinimumSize(800,600)
# widget of central area
centralArea = QWidget()
centralArea.setStyleSheet("background: #5A5E6B")
self.setCentralWidget(centralArea)
# textbox implementation
textBox1 = QLineEdit("", centralArea)
textBox1.setStyleSheet('background: lightgrey;'
'color: red;')
textBox1.setGeometry(200, 90, 270, 30)
textBox1.textEdited.connect(self.getTextInTextBox) # signal = "textEdited"
# my own slot = "getTextInTextBox"
# slots definition
@Slot(str)
def getTextInTextBox(self, txt: str):
textRecovering: QLineEdit = self.sender()
print(f"Text in the textbox is '{textRecovering.text()}'")
return textRecovering.text()
# should i define a setter / getter ?
if __name__ == "__main__":
app = QApplication(sys.argv)
MyWindow = MyMainWindow()
MyWindow.show()
#implementedText = MyWindow .getTextInTextBox()
sys.exit(app.exec())Error:TypeError: MyMainWindow.getTextInTextBox() missing 2 required positional arguments: 'self' and 'txt'
