
from lib.login import Login


def pychat():
    login = Login
    login()
                    

if __name__ == '__main__':
    pychat()


from lib.login import Login
from lib.client import Client
from Tkinter import *


class PyChat(object):

    def __init__(self):
        self.root = Tk()
        self.root.geometry("300x275+400+100")

    def login(self):
        self.login = Login(self.root, self.create_client)

    def run(self):
        self.root.mainloop()

    def create_client(self):
        credentials = self.login.login_credentials()
        credentials['root'] = self.root
        self.reset()
        self.client = Client(**credentials)

    def reset(self):
        for element in self.root.winfo_children():
            element.destroy()
                    

if __name__ == '__main__':
    pychat = PyChat()
    pychat.login()
    pychat.run()

Rework to have a central root window controlled from a top class
Rework to have a central root window controlled from a top class

  
  from lib.login import Login
+ from lib.client import Client
+ from Tkinter import *
  
  
- def pychat():
-     login = Login
-     login()
+ class PyChat(object):
+ 
+     def __init__(self):
+         self.root = Tk()
+         self.root.geometry("300x275+400+100")
+ 
+     def login(self):
+         self.login = Login(self.root, self.create_client)
+ 
+     def run(self):
+         self.root.mainloop()
+ 
+     def create_client(self):
+         credentials = self.login.login_credentials()
+         credentials['root'] = self.root
+         self.reset()
+         self.client = Client(**credentials)
+ 
+     def reset(self):
+         for element in self.root.winfo_children():
+             element.destroy()
                      
  
  if __name__ == '__main__':
+     pychat = PyChat()
+     pychat.login()
-     pychat()
+     pychat.run()
  
Rework to have a central root window controlled from a top class
## Code Before:

from lib.login import Login


def pychat():
    login = Login
    login()
                    

if __name__ == '__main__':
    pychat()

## Instruction:
Rework to have a central root window controlled from a top class
## Code After:

from lib.login import Login
from lib.client import Client
from Tkinter import *


class PyChat(object):

    def __init__(self):
        self.root = Tk()
        self.root.geometry("300x275+400+100")

    def login(self):
        self.login = Login(self.root, self.create_client)

    def run(self):
        self.root.mainloop()

    def create_client(self):
        credentials = self.login.login_credentials()
        credentials['root'] = self.root
        self.reset()
        self.client = Client(**credentials)

    def reset(self):
        for element in self.root.winfo_children():
            element.destroy()
                    

if __name__ == '__main__':
    pychat = PyChat()
    pychat.login()
    pychat.run()
