I'm creating an application that requires multiple tkinter windows. The code below works the way how I want it to work, but I'm not sure if I'm doing it in the proper way.

The first window (and in this case, the main window as well) contains three buttons as of now, 1 label which acts as a title, and a treeview.

The "Add Member" button is the only button that has functionality as of now. When clicked, it will pop a new window. That said window contains label.

To sum it up, I would like to humbly ask if I'm doing it properly, or there is a better and more accurate way of writing this code.

class Application(tk.Frame):
    def __init__(self,parent,*args,**kwargs):
        self.parent = parent
        self.parent.title("Senior Citizen Association")

        ttk.Label(text="SENIOR CITIZEN ASSOCIATION").grid(row=0,column=0,columnspan=5,sticky="n")

        self.tree = ttk.Treeview(height=15,column=("First Name","Middle Initial","Last Name"))
        self.tree.heading("#0",text="First Name",anchor="w")
        self.tree.heading("#1",text="Middle Initial",anchor="w")
        self.tree.heading("#2",text="Last Name",anchor="w")

    def add_member(self):
        self.addMemberWindow = tk.Toplevel(self.parent)
        self.addClass = NewMember(self.parent,self.addMemberWindow)

class NewMember(tk.Frame):
    def __init__(self,parent,child,*args,**kwargs):
        self.parent = parent
        self.child = child
        self.child.title("Add Member")

        ttk.Label(self.child,text="Add Member").grid(row=0,column=0,sticky="nsew")

if __name__ == "__main__":
    app = tk.Tk()

For me, it is a pretty piece of code. I learned much from it. Also, I'm not sure if it is a proper way. But, it works fine and is easy to read :)

  • 2
    \$\begingroup\$ Welcome to Code Review! Could you expand upon this? Perhaps explain what makes it easy to read... \$\endgroup\$ Oct 4 '19 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.