我正在嘗試實現一個功能。我的代碼如下。如何在字符串中按QpushButton時在QlineEdit中獲取文本?
我想在字符串中使用objectname'host'代替lineed中的文本,當用戶單擊名爲'connect'的按鈕時,會說'shost'。我怎樣才能做到這一點?我嘗試失敗了。我如何實現這個功能?
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
le = QLineEdit()
le.setObjectName("host")
le.setText("Host")
pb = QPushButton()
pb.setObjectName("connect")
pb.setText("Connect")
layout.addWidget(le)
layout.addWidget(pb)
self.setLayout(layout)
self.connect(pb, SIGNAL("clicked()"),self.button_click)
self.setWindowTitle("Learning")
def button_click(self):
#i want the text in lineedit with objectname
#'host' in a string say 'shost'. when the user click
# the pushbutton with name connect.How do i do it?
# I tried and failed. How to implement this function?
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
現在我該如何實現函數「button_click」?我剛開始使用pyQt!
如果您發佈實際可用的代碼片段,您更有可能得到回覆。 – brianz 2010-06-10 20:04:18