[英]How to get input entered in QLineEdit by clicking QPushButton and then print result in QLabel?
[英]How to print input of QLineEdit/ store in variable?
如何打印QLineEdit
的輸入? 還是將其存儲為變量供以后在函數中使用?
這是我嘗試過的:
self.QLineEdit.text()
我的完整代碼真的很混亂,如果有人在某個地方有一個示例,我將非常感激。 我的代碼未返回任何文本。
不確定您的意思是什么,但是這是一個在類中顯示QLineEdit的示例,該示例顯示如何返回值並存儲它。
from PyQt import QtGui
class SimpleExample(object):
def __init__(self):
# instance line edit
self.line_edit = QtGui.QLineEdit()
def pretend_something_happened(self):
# User Did something
self.line_edit.setText("User Entered Something")
def line_value(self):
# return text value of line edit
return self.line_edit.text()
if __name__ == '__main__':
s = SimpleExample()
# Store Value
val = s.line_value()
print(val)
s.pretend_something_happened()
# Print Value to show the value was copied
print(val)
# Store new value
val = s.line_value()
print(val)
如@Andrew Paxson的答案中所述,您不能使用self.QLineEdit
。 您的窗口中必須有一個實例:
self.line_edit = QtGui.QLineEdit()
那么您可以使用self.line_edit.text
來存儲或打印其值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.