lloydyu24
lloydyu24

Reputation: 839

How to close window / widget properly after opening another window (.py file) in 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.")

I want to close the log-in window after the user enters the correct login details. The window tries to close but freezes and becomes unresponsive.

This is what happens.

My problem is how can I close the Log In form without causing it to be unresponsive? (If my code sample is lacking from where you can understand the problem, please tell me. Thank you!)

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

Upvotes: 0

Views: 54

Answers (1)

eyllanesc
eyllanesc

Reputation: 243887

The call function waits for the return code, so forcing to close the process that launches the new application generates that behavior. You should use Popen instead of call.

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

Upvotes: 1

Related Questions