2016-09-30 8 views
-2

メインウィンドウにLineEdit11とbutton1でMainWindowを作成しました。また、私はLineEditとボタン2でV1フォーム2を作成しました。LineEdit1(Form1)からLineEdit2(Form2)へのテキスト_ Python、PyQt

ボタン1を押し上げるとフォーム2が表示されます。私はlineEditにテキストを書き、私はcliked Button2によってForm1のLineEdit11にテキストを転送したい。それらを接続する方法?

のPython 3.5、PyQtは4

ので、私はV1クラスで

def wyslij(self): 
     self.lineEdit.setText(self.Ui_Form.lineEdit_11.text()) 

を書き、私はエラーを取得

OK事前にありがとう:

'Ui_V1' object has no attribute 'Ui_Form' Of course i add V1 class into Ui_Form. V1 is second window and Ui_Form is main window.

です全体コード:

from PyQt4 import QtCore, QtGui 
from V1 import Ui_V1 
from V2 import Ui_V2 
from V3 import Ui_V3 

try: 
    _fromUtf8 = QtCore.QString.fromUtf8 
except AttributeError: 
    def _fromUtf8(s): 
     return s 

try: 
    _encoding = QtGui.QApplication.UnicodeUTF8 
    def _translate(context, text, disambig): 
     return QtGui.QApplication.translate(context, text, disambig, _encoding) 
except AttributeError: 
    def _translate(context, text, disambig): 
     return QtGui.QApplication.translate(context, text, disambig) 

# V1 window 
class Ui_V1(object): 
    def setupUi(self, V1): 
     V1.setObjectName(_fromUtf8("V1")) 
     V1.resize(400, 300) 
     self.label = QtGui.QLabel(V1) 
     ... 
     self.pushButton.setText(_translate("V1", "Wyslij", None)) 
     self.pushButton_2.setText(_translate("V1", "Wyslij", None)) 
     self.pushButton.clicked.connect(lambda: self.wyslij()) 

    def wyslij(self): 
     self.lineEdit.setText(self.Ui_Form.lineEdit_11.text()) 



# V2 okno 
class Ui_V2(object): 
    def setupUi(self, V2): 
     V2.setObjectName(_fromUtf8("V2")) 
     V2.resize(400, 300) 
     self.label_4 = QtGui.QLabel(V2) 
     ... 
     self.pushButton.setText(_translate("V2", "Wyslij", None)) 
     self.label.setText(_translate("V2", "V2", None)) 
     self.label_3.setText(_translate("V2", "A", None)) 
     self.pushButton_2.setText(_translate("V2", "Wyslij", None)) 

# V3 okno 
class Ui_V3(object): 
    def setupUi(self, V3): 
     V3.setObjectName(_fromUtf8("V3")) 
     V3.resize(400, 300) 
     self.label_4 = QtGui.QLabel(V3) 
     ... 
     self.pushButton.setText(_translate("V3", "Wyslij", None)) 
     self.label.setText(_translate("V3", "V3", None)) 
     self.label_3.setText(_translate("V3", "A", None)) 
     self.pushButton_2.setText(_translate("V3", "Wyslij", None)) 



# Main window! 
class Ui_Form(object): 
    def setupUi(self, Form): 
     Form.setObjectName(_fromUtf8("Form")) 
     Form.resize(728, 601) 
     Form.setMinimumSize(QtCore.QSize(728, 601)) 
     self.label_6 = QtGui.QLabel(Form) 
     self.label_6.setGeometry(QtCore.QRect(169, 3, 401, 41)) 
     self.label_6.setObjectName(_fromUtf8("label_6"))... 


    def retranslateUi(self, Form): 
     Form.setWindowTitle(_translate("Form", "Form", None)) 
     self.label_6.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:16pt; font-weight:600;\">TYGODNIOWA KONTROLA JAKOSCI</span></p></body></html>", None)) 
     self.label_8.setText(_translate("Form", "(dd-mm-rrrr)", None))... 

     self.pushButton_2.clicked.connect(lambda: self.zapis_tyg()) # Do zapisu do tyg formularza 
     self.pushButton_5.clicked.connect(lambda: self.openV1()) # Do pojawienia si eokna V1 
     self.pushButton_6.clicked.connect(lambda: self.openV2()) # Do pojawienia si eokna V2 
     self.pushButton_7.clicked.connect(lambda: self.openV3()) # Do pojawienia si eokna V3 

    #zapis do pliku formularza tyg 
    def zapis_tyg(self): # ZAPIS DO FORMULARZ TYGODNIOWEGO 
     s = "" 
     seq = (self.comboBox_6.currentText(), ".txt"); # This is sequence of strings. laczenie aby nazywał pliki wzaleznosci od aparatu 
     a= s.join(seq) 
     text_file = open(a , "a") 
     text_file.write(self.lineEdit.text()+ "\t") #data 
     text_file.write(self.lineEdit_2.text()+ "\t") #osoba 
     text_file.write(self.comboBox_6.currentText() + "\t") #aparat 
     text_file.write(self.comboBox.currentText() + "\t") #AKCESORIUM 
     text_file.write(self.comboBox_2.currentText() + "\t") #ZAB ANTYK 
     text_file.write(self.comboBox_3.currentText() + "\t") #iZO 
     text_file.write(self.comboBox_4.currentText() + "\t")# CENTRQTOR 
     text_file.write(self.comboBox_5.currentText() + "\t")# TELEMETR 
     text_file.write(self.textEdit.toPlainText()+ "\n") # KOM MECH 
     text_file.close() 

    #function to show a new form 
    def openV1(self): 
     self.V1Window=QtGui.QMainWindow() 
     self.ui= Ui_V1() 
     self.ui.setupUi(self.V1Window) 
     self.V1Window.show() 

    def openV2(self): 
     self.V2Window=QtGui.QMainWindow() 
     self.ui= Ui_V2() 
     self.ui.setupUi(self.V2Window) 
     self.V2Window.show() 

    def openV3(self): 
     self.V3Window=QtGui.QMainWindow() 
     self.ui= Ui_V3() 
     self.ui.setupUi(self.V3Window) 
     self.V3Window.show() 

そして、このライン:

def wyslij(self): 
     self.lineEdit.setText(self.Ui_Form.lineEdit_11.text()) 

正常に動作しません。任意のコードの最も簡単な方法(ただし、最高の)なし

+0

あなたは良い答えをしたい場合は、いくつかが来る示す必要があります – PyNico

答えて

0

はそのようなものになるだろう:

def on_button2_click(self): 
    self.form2.lineEdit2.setText(self.lineEdit1.text()) 
関連する問題