[英]Basic Widget Interaction with PyQt
Please can someone tell me what im doing wrong here with respect to calling pwTxt.text. 请有人告诉我在调用pwTxt.text时我在做什么错。
#!/usr/bin/python
import sys
from PyQt4 import QtCore, QtGui
from mainwindow import Ui_MainWindow
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def on_pwExtract_pressed(self):
print self.pwTxt.text
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
The line print self.pwTxt.text
fails because it can't find the widget, pwTxt is a QLineEdit defined on the main window. 行
print self.pwTxt.text
失败,因为它找不到小部件,pwTxt是在主窗口上定义的QLineEdit。 I just made it in QTDesigner and generated python code with pyuic4. 我只是在QTDesigner中创建并使用pyuic4生成了python代码。
How do I correctly reference other widgets on the same window, in this case I just want to get the text from a QLineEdit named pwTxt when the QPushButton pwExtract is pressed. 如何正确引用同一窗口上的其他小部件,在这种情况下,我只想在按下QPushButton pwExtract时从名为pwTxt的QLineEdit中获取文本。
Thanks a lot. 非常感谢。
尝试:
print self.ui.pwTxt.text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.