Displaying 2nd Window Issue

我是研究僧i 提交于 2019-12-02 11:06:03

问题


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: The event loop is already running

and once i pressed enter on the terminal it pop up the other window .

I am confuse where i am wrong .

Thanks test.py gui1.py


回答1:


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()


来源:https://stackoverflow.com/questions/11996478/displaying-2nd-window-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!