How it works...

Most of the code of this recipe have already been covered in other recipes, and the main difference is contained in the open() method of the UserForm class, where we moved the call to grab_set(). However, the wait_window() method is what actually stops the execution and prevents us from returning the data before the form has been modified:

    def open(self):
self.grab_set()
self.wait_window()
username = self.username.get()
password = self.password.get()
return User(username, password, self.user_type)

It is important to remark that wait_window() enters a local event loop, which finishes when the window is destroyed. Although it is possible to pass the widget we want to wait to be removed, we can omit it to implicitly refer to the instance that calls this method.

When the UserForm instance is destroyed, the execution of the open() method continues, and it returns the User object that can now be used in the App class:

    def open_window(self):
window = UserForm(self, self.user_type.get())
user = window.open()
print(user)

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset