在GUI中调用另一个GUI

时间:2015-02-17 04:52:00

标签: python user-interface pyqt

我有两个使用qt-designer创建的GUI,我将其转换为python - anmUi.py和anmInfoUI.py

虽然我可以通过运行以下内容导入两个并打开anmUi

import sys
sys.path.insert(0, '/user_data/test/anm/versions')
import anmTool_v01a
reload(anmTool_v01a)
win = anmTool_v01a.anmUi()
win.show()

然而,我无法打开第二个gui - anmInfoUI,它将由第一个gui中的按钮启动。

我尝试使用与第一个gui类似的格式编写,但当我尝试使用.exec运行时,我收到错误,例如# AttributeError: 'module' object has no attribute 'exec_'

class anmUi(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self, parent = None, modal = False)
        self.ui = anmUi.Ui_Migration()
        self.ui.setupUi(self)
        self.createConnections()


    def createConnections(self):
        self.connect(self.ui.pushButton_editSelected, QtCore.SIGNAL('clicked()'), self.editSelected)


    def editSelected(self):
        selected_item = self.ui.treeWidget_migrateAnmg.selectedItems()
        if selected_item:
            anmInfoUI.exec_()


class anmInfoUI(QtGui.QDialog):

    def __init__(self, parent = None, modal = False):
        QtGui.QWidget.__init__(self, parent, modal = modal)

        self.ui = anmInfoUI.Ui_EditInfo()
        self.ui.setupUi(self)

如何让它运行?

2 个答案:

答案 0 :(得分:0)

exec_()是您在Qt应用程序上调用的内容。在您的情况下,应用程序已在运行(否则您根本看不到任何窗口),而是要实例化新窗口小部件/窗口并调用其show()方法。

答案 1 :(得分:0)

此代码成功打开新窗口。

class anmUi(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self, parent = None, modal = False)
        self.ui = Ui_Migration()
        self.ui.setupUi(self)
        self.createConnections()


    def createConnections(self):
        self.connect(self.ui.pushButton_editSelected, QtCore.SIGNAL('clicked()'), self.editSelected)


    def editSelected(self):
        selected_item = self.ui.treeWidget_migrateAnmg.selectedItems()
        if True:
            self.child = anmInfoUI()
            self.child.show()

    def slot_cancel(self, *args):
        pass


class anmInfoUI(QtGui.QDialog):

    def __init__(self, parent = None, modal = False):
        QtGui.QWidget.__init__(self, parent, modal = modal)

        self.ui = Ui_EditAsset()
        self.ui.setupUi(self)

注意使用True(我不想填充您的选择框)。您可以使用其标志来控制新窗口是否是模态的。