在PyQt5中,QLineEdit控件可以输入数据,想把输入的数据保存下来,搜索已知有实时获取输入文本的方式,代码如下:
用代码块功能插入代码,请勿粘贴截图
def onChange(self):
ls=[]
facename = self.edt_user.text()
ls.append(facename)
def onChange(self):
ls=[]
facename = self.edt_user.text()
ls.append(facename)
在 PyQt5 中,如果您希望获取用户在 QLineEdit 控件中最终输入的文本,您可以使用该控件的 text()
方法。例如:
lineedit = QLineEdit()
# Get the text entered by the user
text = lineedit.text()
text()
方法返回的是一个字符串,因此如果您希望在获取文本后对其进行更改,您可能需要对字符串进行操作。如果您希望在用户在文本框中输入或更改文本时进行处理,您可以将信号与槽连接起来,以便在每次用户输入或更改文本时调用特定的函数。例如:
lineedit = QLineEdit()
# Define a function to be called whenever the user changes the text in the line edit
def on_text_changed(text):
print(f"The new text is: {text}")
# Connect the textChanged signal to the on_text_changed slot
lineedit.textChanged.connect(on_text_changed)
请注意,在此示例中,我们将函数 on_text_changed
与 textChanged
信号连接起来,这样每当用户在文本框中更改文本时,该函数就会自动调用。