如何从Qtdesign初始化python代码

2024-09-29 18:36:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须为我正在进行的项目制作一个GUI。既然我不是程序员,请原谅我的问题。你知道吗

我使用Qt设计器创建了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\u main对话框。我希望你能帮助我。你知道吗

敬礼


Tags: selfnonetranslatecoordinatesqtguiqapplicationmesherqtcore

热门问题