我正在尝试使用以下代码从表格 2 中 LineEdit 的值更新表格 1 中的标签。它没有给我任何错误,但值只是没有得到更新。有什么我做错了吗?
主要.py:
import First,Second
import sys
from PySide import QtGui,QtCore
class ControlWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(ControlWidget, self).__init__(parent)
self.ui = First.Ui_Form()
self.ui.setupUi(self)
def setValues(self,value):
print value
print "HEre"
self.ui.label.setText(value)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mySW = ControlWidget()
mySW.show()
sys.exit(app.exec_())
首先.py:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'First.ui'
#
# Created: Wed Nov 01 16:37:02 2000
# by: pyside-uic 0.2.15 running on PySide 1.2.1
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
import Second
class Ui_Form(QtGui.QWidget):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(160, 92)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(40, 20, 75, 23))
self.pushButton.setObjectName("pushButton")
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(50, 60, 46, 13))
self.label.setObjectName("label")
QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.showseconddiag)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def showseconddiag(self):
self.Diag = QtGui.QDialog(self)
self.secondinstance = Second.Ui_Form(self)
self.secondinstance.setupUi(self.Diag)
self.Diag.show()
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
第二个.py:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Second.ui'
#
# Created: Wed Nov 01 16:37:16 2000
# by: pyside-uic 0.2.15 running on PySide 1.2.1
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
import First,main
class Ui_Form(QtGui.QWidget):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(191, 94)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(40, 20, 75, 23))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtGui.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(30, 50, 113, 20))
self.lineEdit.setObjectName("lineEdit")
QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.returnvalue)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def returnvalue(self):
self.finstance = main.ControlWidget(self)
self.finstance.setValues(self.lineEdit.text())
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))