Python 调用GUI中的另一个GUI
我使用qt设计器创建了两个GUI,并将其转换为python-anmUi.py和anmInfoUI.py 而我可以通过运行以下命令导入并打开Python 调用GUI中的另一个GUI,python,user-interface,pyqt,Python,User Interface,Pyqt,我使用qt设计器创建了两个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将由第
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中的按钮启动
我尝试以与第一个gui类似的格式编写,但当我尝试使用.exec
运行它时,出现了错误,例如\AttributeError:“module”对象没有属性“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)
如何让它运行?
exec()
是您在Qt应用程序上调用的东西。在您的情况下,应用程序已经在运行(否则您将看不到任何窗口),您希望实例化新的小部件/窗口,并调用其show()
方法。此代码成功打开新窗口
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的用法(我不想填充您的选择框)。您可以使用其标志来控制新窗口是否为模式窗口。请提供调用
exec\ucode>但不起作用的代码(所有相关代码)。在任何人能够帮助你之前,知道你在做什么是必要的you@three_pineapples如上所述,我已经在我的帖子中编辑了代码。如果您包含更多的代码,尽可能少地重现问题,我们可以给您一个更准确的答案。使用show()
对我不起作用。。。这是我的第一个UI的python代码,而这是我的第二个UI的python代码。当我尝试使用show()
时,虽然我没有收到任何错误,但第二个UI没有显示。MGtool没有从您提供的代码运行('QDialog'对象没有属性'slot\u cancel'
),很抱歉回复太晚。我创建了一个名为“slot\u cancel”的函数。。可能您可以为它创建一个快速函数,也可以在UI代码中删除它。这两种方法都应该奏效