显示第二个窗口问题 [英] Displaying 2nd Window Issue
问题描述
我正在处理 2 个窗口.一个是由 Qt Designer 创建的,我将其导入在 test.py 程序上.我做了什么我在测试程序上做了一个小部件比添加一个按钮,点击事件我尝试弹出另一个窗口(gui1.py)由 Qt Designer 创建,但它从不弹出,当我使用时中断并逐行调试它在运行后向我显示此消息在第 35 行 test.py 上执行此命令myapp2 = MyForm()".
I am dealing with 2 windows . One is created by Qt Designer and i import it on test.py program . what i did i make a Widget on the test program and than add a button to it and on click event I try to popup the other window(gui1.py) created by Qt Designer but it never pop ups and when i use break and do line by line debugging it shows me this message after running this command "myapp2 = MyForm()" on line number 35 test.py .
QCoreApplication::exec:事件循环已经在运行
QCoreApplication::exec: The event loop is already running
一旦我在终端上按下回车键,它就会弹出另一个窗口.
and once i pressed enter on the terminal it pop up the other window .
我很困惑我错在哪里.
推荐答案
另一个窗口没有出现的原因是因为你没有保留对它的引用,所以它在显示后立即被垃圾收集.
The reason the other window doesn't appear, is because you are not keeping a reference to it, and so it gets garbage-collected immediately after it is shown.
要解决这个问题,您可以将窗口实例存储为一个属性,或者给它一个父级:
To fix the problem, you could either store the window instance it as an attribute, or give it a parent:
def local_manag(self):
print "pressed"
# store it as an attribute
self.myapp2 = MyForm()
self.myapp2.show()
# or give it a parent
# myapp2 = MyForm(self)
# myapp2.show()
这篇关于显示第二个窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!