我試圖設計數據輸入窗體,當文本輸入到行編輯窗口小部件時按下ok按鈕時將向文本添加文本,但是答案是完全躲避我:pyqt4如何設置文本從行編輯到按鈕上的標籤單擊
#!/usr/bin/python3
#-*- coding: utf-8 -*-
"""
Set label text from line edit with
ok click
"""
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.qle = QtGui.QLineEdit(self)
self.qle.move(100, 0)
sometext = self.qle.text
self.lbl = QtGui.QLabel(self)
self.lbl.move(100, 100)
btn = QtGui.QPushButton("Ok", self)
btn.move(30, 100)
btn.clicked.connect(self.buttonClicked)
self.setGeometry(200, 200, 300, 200)
self.show
def buttonClicked(self, sometext):
sender = self.sender()
self.lbl.setText(sometext)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
請問您如何得到這個工作?
'self.lbl.setText(self.qle.text())'。 – ekhumoro