2016-04-27 39 views
0

我必須爲我正在開發的項目製作GUI。由於我不是程序員,請原諒我的問題。如何從Qt設計器初始化python代碼

我使用Qt-designer創建了GUI。我還成功地編譯的.ui文件的.py

from PySide import QtCore, QtGui 

class Ui_Mesher(object): 
    def setupUi(self, Mesher): 
     Mesher.setObjectName("Mesher") 
     Mesher.resize(480, 555) 
     self.pushButton = QtGui.QPushButton(Mesher) 
     self.pushButton.setGeometry(QtCore.QRect(130, 510, 101, 23)) 
     self.pushButton.setObjectName("pushButton") 
     self.pushButton_2 = QtGui.QPushButton(Mesher) 
     self.pushButton_2.setGeometry(QtCore.QRect(240, 510, 101, 23)) 
     self.pushButton_2.setObjectName("pushButton_2") 
     self.pushButton_3 = QtGui.QPushButton(Mesher) 
     self.pushButton_3.setGeometry(QtCore.QRect(320, 450, 75, 23)) 
     self.pushButton_3.setObjectName("pushButton_3") 
     self.comboBox = QtGui.QComboBox(Mesher) 
     self.comboBox.setGeometry(QtCore.QRect(10, 450, 131, 22)) 
     self.comboBox.setAcceptDrops(False) 
     self.comboBox.setObjectName("comboBox") 
     self.comboBox.addItem("") 
     self.comboBox.addItem("") 
     self.comboBox.addItem("") 
     self.comboBox.addItem("") 
     self.comboBox.addItem("") 
     self.groupBox = QtGui.QGroupBox(Mesher) 
     self.groupBox.setGeometry(QtCore.QRect(10, 10, 461, 351)) 
     self.groupBox.setObjectName("groupBox") 
     self.add_coordinates_button = QtGui.QPushButton(self.groupBox) 
     self.add_coordinates_button.setGeometry(QtCore.QRect(190, 100, 51, 41)) 
     icon = QtGui.QIcon() 
     icon.addPixmap(QtGui.QPixmap("../../Icons/green-right-arrow-clip-art-6842.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 
     self.add_coordinates_button.setIcon(icon) 
     self.add_coordinates_button.setObjectName("add_coordinates_button") 
     self.list_coordinates = QtGui.QListWidget(self.groupBox) 
     self.list_coordinates.setGeometry(QtCore.QRect(280, 20, 161, 192)) 
     self.list_coordinates.setObjectName("list_coordinates") 
     self.input_x_coordinate = QtGui.QLineEdit(self.groupBox) 
     self.input_x_coordinate.setGeometry(QtCore.QRect(40, 110, 51, 20)) 
     self.input_x_coordinate.setObjectName("input_x_coordinate") 
     self.input_y_coordinate = QtGui.QLineEdit(self.groupBox) 
     self.input_y_coordinate.setGeometry(QtCore.QRect(100, 110, 51, 20)) 
     self.input_y_coordinate.setObjectName("input_y_coordinate") 

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

     def retranslateUi(self, Mesher): 
      Mesher.setWindowTitle(QtGui.QApplication.translate("Mesher", "Mesher", None, QtGui.QApplication.UnicodeUTF8)) 
      self.pushButton.setText(QtGui.QApplication.translate("Mesher", "Save Changes", None, QtGui.QApplication.UnicodeUTF8)) 
      self.pushButton_2.setText(QtGui.QApplication.translate("Mesher", "Exit", None, QtGui.QApplication.UnicodeUTF8)) 
      self.pushButton_3.setText(QtGui.QApplication.translate("Mesher", "Import", None, QtGui.QApplication.UnicodeUTF8)) 
      self.comboBox.setItemText(0, QtGui.QApplication.translate("Mesher", "Engrid", None, QtGui.QApplication.UnicodeUTF8)) 
      self.comboBox.setItemText(1, QtGui.QApplication.translate("Mesher", "Gmsh", None, QtGui.QApplication.UnicodeUTF8)) 
      self.comboBox.setItemText(2, QtGui.QApplication.translate("Mesher", "Salome", None, QtGui.QApplication.UnicodeUTF8)) 
      self.comboBox.setItemText(3, QtGui.QApplication.translate("Mesher", "Abaqus", None, QtGui.QApplication.UnicodeUTF8)) 
      self.comboBox.setItemText(4, QtGui.QApplication.translate("Mesher", "Ansys", None, QtGui.QApplication.UnicodeUTF8)) 
      self.groupBox.setTitle(QtGui.QApplication.translate("Mesher", "EzMesher", None, QtGui.QApplication.UnicodeUTF8)) 
      self.add_coordinates_button.setText(QtGui.QApplication.translate("Mesher", "Create geometry", None, QtGui.QApplication.UnicodeUTF8)) 


Ui_Mesher() 

我想在我喜歡的主文件將其初始化:

from PySide.QtCore import * 
from PySide.QtGui import * 
import sys 

import Gui_mesh 

class MainDialog(QDialog, Gui_mesh.Ui_mainDialog): 

def __init__(self, parent = None): 

    super(MainDialog, self).__init__(parent) 
    self.setupUi(self) 

app = QApplication(sys.argv) 
form = MainDialog() 
form.show() 
app.exec_() 

但顯然我不能使用Ui_mainDialog。我希望你能幫助我。

問候

+0

請發佈錯誤堆棧跟蹤。 –

+0

AttributeError:'模塊'對象沒有屬性'Ui_mainDialog' –

回答

1

我想你應該從編譯.py文件使用正確的名字嗎?

class MainDialog(QDialog, Gui_mesh.Ui_Mesher) 
+0

好吧,這是令人尷尬的。但非常感謝你 –

+0

不客氣;) – salomonderossi