2017-04-14 17 views
0
from PyQt4 import QtCore, QtGui 

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) 

class Ui_Dialog(object): 
    def setupUi(self, Dialog): 
     Dialog.setObjectName(_fromUtf8("Dialog")) 
     Dialog.resize(833, 592) 
     self.label = QtGui.QLabel(Dialog) 
     self.label.setGeometry(QtCore.QRect(5, 9, 1366, 700)) 
     self.label.setText(_fromUtf8("")) 
     self.label.setPixmap(QtGui.QPixmap(_fromUtf8("H:/Community/images/Library-Books2.jpg"))) 
     self.label.setScaledContents(True) 
     self.label.setObjectName(_fromUtf8("label")) 
     self.label_2 = QtGui.QLabel(Dialog) 
     self.label_2.setGeometry(QtCore.QRect(40, 90, 91, 31)) 
     font = QtGui.QFont() 
     font.setFamily(_fromUtf8("Plantagenet Cherokee")) 
     font.setPointSize(14) 
     font.setBold(True) 
     font.setWeight(75) 
     self.label_2.setFont(font) 
     self.label_2.setObjectName(_fromUtf8("label_2")) 
     self.lineEdit = QtGui.QLineEdit(Dialog) 
     self.lineEdit.setGeometry(QtCore.QRect(160, 90, 361, 31)) 
     font = QtGui.QFont() 
     font.setFamily(_fromUtf8("Arial")) 
     font.setPointSize(9) 
     self.lineEdit.setFont(font) 
     self.lineEdit.setObjectName(_fromUtf8("lineEdit")) 
     self.pushButton = QtGui.QPushButton(Dialog) 
     self.pushButton.setGeometry(QtCore.QRect(540, 92, 51, 31)) 
     self.pushButton.setText(_fromUtf8("")) 
     icon = QtGui.QIcon() 
     icon.addPixmap(QtGui.QPixmap(_fromUtf8("H:/Community/community/Library/build/classes/library/search.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) 
     self.pushButton.setIcon(icon) 
     self.pushButton.setFlat(False) 
     self.pushButton.setObjectName(_fromUtf8("pushButton")) 
     self.plainTextEdit = QtGui.QPlainTextEdit(Dialog) 
     self.plainTextEdit.setGeometry(QtCore.QRect(10, 140, 900, 391)) 
     self.plainTextEdit.setBackgroundVisible(False) 
     self.plainTextEdit.setCenterOnScroll(False) 
     self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit")) 
     self.pushButton_2 = QtGui.QPushButton(Dialog) 
     self.pushButton_2.setGeometry(QtCore.QRect(410, 540, 90, 50)) 
     self.pushButton_2.setText(_fromUtf8("")) 
     self.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.open) 
     icon1 = QtGui.QIcon() 
     icon1.addPixmap(QtGui.QPixmap(_fromUtf8("H:/Community/images/new-button3 - Copy.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) 
     self.pushButton_2.setIcon(icon1) 
     self.pushButton_2.setIconSize(QtCore.QSize(80, 80)) 
     self.pushButton_2.setFlat(True) 
     self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) 

     self.retranslateUi(Dialog) 
     QtCore.QMetaObject.connectSlotsByName(Dialog) 

    def open(self): 

     fileName = QtGui.QFileDialog.getOpenFileName(self, 'OpenFile') 
     self.LineEdit.setText(fileName) 
     print(fileName) 

    def retranslateUi(self, Dialog): 
     Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) 
     self.label_2.setText(_translate("Dialog", "FileName", None)) 
+0

上記のいずれかがエラーを与えている:「Cファイル:/ユーザー(self.pushButton、QtCore.SIGNAL( 'clicked()')、self.open AttributeError: 'Ui_Dialog'オブジェクトには属性がありません '接続 '...実際に私はファイルを選択したいボタンをクリックした後... plzz help – Pooja

答えて

0

一般に、私は一緒に働いているウィンドウを持っているとき、私は他の親として1を設定し、もう一方からデータを受け取るメソッドを持っています。たとえば:

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): 
    def __init__(self): 
     QtWidgets.QMainWindow.__init__(self) 
     self.setupUi(self) 
     self.run_btn.clicked.connect(self.setup_project) 

    def setup_project(self): 
     self.project = ProjectParams(parent=self) 
     self.project.show() 
     if self.project.exec_() == QtWidgets.QDialog.Accepted: 
      self.params = self.project.params 
      self.loops = self.project.loops 

class ProjectParams(QtWidgets.QDialog, Ui_ProjectParams): 
    def __init__(self, parent=None): 
     QtWidgets.QDialog.__init__(self, parent=parent) 
     self.setupUi(self) 
     self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False) 
     self.params = {} 

あなたのエラーから、私はあなたが変更する必要があると思うだろう:

self.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.open) 

に:

self.pushButton.clicked.connect(self.open) 
+0

とsirは、これらの2つのウィンドウを接続する方法を教えてくれます。 – Pooja

関連する問題