PyQT copy text from form1 to form2
Dear Friends. I wrote a program that have Form and Form2 called V1. V1 will show after cliked button in Form1.
In V1 I have a LineEdit and button. When i wrote something in LineEdit in V1 I want send this text to LineEdit in Form1.
Code:
from PyQt4 import QtCore, QtGui
from V1 import Ui_V1
try:
_fromUtf8
= QtCore.
QString.
fromUtf8except AttributeError:
def _fromUtf8(s):
return s
try:
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.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())
# 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()) # v1 window
#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.ui= Ui_V1()
self.ui.setupUi(self.V1Window)
self.V1Window.show()
I had an error:
'Ui_V1' object has no attribute 'Ui_Form'
Where is the problem?
Thank you
Re: PyQT copy text from form1 to form2
First, this looks like you have edited the generated class instead of just using it.
Second, as Python tells you, your Ui_V1 class does not have any member called Ui_Form.
Cheers,
_
Re: PyQT copy text from form1 to form2
Thanks for reply
I am beginner in python and in GUI :) so that why i am writinig in code in this class instead of creating second file only with functions.
so how to conect Ui_V1 wiht Ui_Form ? Because i coonected button with Ui_V1 but i cant connect button with Labels...
Re: PyQT copy text from form1 to form2
If you want to access "self.Ui_Form" then you need to initizalize this.
Something like
Code:
self.Ui_Form = Ui_Form()
Cheers,
_
Re: PyQT copy text from form1 to form2
Ok so I have done it :
Quote:
def wyslij(self):
self.kopiaWindow=QtGui.QMainWindow()
self.Ui_Form=Ui_Form()
self.Ui_Form.lineEdit.text()=self.lineEdit.text()
and i have an error:
Quote:
SyntaxError: can't assign to function call
thanks.
Re: PyQT copy text from form1 to form2
Yes, last line of your new code.
You are trying to assign to the function text()
You probably want to assign to the property text instead.
Cheers,
_
Re: PyQT copy text from form1 to form2
So how i cantransfer text from lineEdit (V1 Form) to lineEdit ( Ui_form)?
Thanks
Re: PyQT copy text from form1 to form2
Either by assiging to the target's text property or by calling the target's setText function.
Cheers,
_
Re: PyQT copy text from form1 to form2
could you show me an example how to do this?
Thanks
something like this?
Quote:
self.Ui_Form.lineEdit.text(self.lineEdit.text())
Error:
Quote:
AttributeError: 'Ui_Form' object has no attribute 'lineEdit'
This error is showing when I paste V1 class in MainFile.py but when I separate in two files (of course with import V1/Import MainFile)
Quote:
self.Ui_Form=Ui_Form()
NameError: name 'Ui_Form' is not defined
thanks
Re: PyQT copy text from form1 to form2
Quote:
Originally Posted by
logilink
could you show me an example how to do this?
Maybe you should consider doing a Python tutorial first if you are unclear about assignments or method calls.
Quote:
Originally Posted by
logilink
something like this?
No, QLineEdit does not have a method called "text" that also has arguments.
Why would you even try that?
Quote:
Originally Posted by
logilink
Error:
Which is a different error all together, you are trying to access an object that doesn't exist.
Python is sometimes doing things that are automagically correct, but even Python can't magically create objects.
Cheers,
_