如何在pyQt4中打开另一个窗口(.py文件)后正确关闭窗口/窗口小部件

时间:2017-07-22 05:16:36

标签: python pyqt pyqt4

def run(self, path):
    subprocess.call(['pythonw', path])

def login(self):
    members = {'sample': 'sample'}
    username = self.username.text()
    password = self.password.text()

    if username in members:
        enteredPass = members.get(username)
        if password == enteredPass:
            self.run('inventory.py')
            #app.instance().quit()
            sys.exit()
        else:
            self.username.clear()
            self.password.clear()
            print("Invalid username and password.")
    else:
        self.username.clear()
        self.password.clear()
        print("Invalid username and password.")

我想在用户输入正确的登录详细信息后关闭登录窗口。窗口试图关闭但冻结并变得无法响应。

This is what happens.

我的问题是如何关闭“登录”表单而不会导致其无法响应? (如果我的代码示例缺少您可以理解问题的地方,请告诉我。谢谢!)

Unresponsive. I want it closed after the user enters the correct log in details.

1 个答案:

答案 0 :(得分:1)

call函数等待返回代码,因此强制关闭启动新应用程序的进程会生成该行为。您应该使用Popen代替call

subprocess.Popen(['pythonw', path])