2
\$\begingroup\$

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):
        tk.Frame.__init__(self,parent)
        self.parent = parent
        self.parent.title("Senior Citizen Association")

        ttk.Label(text="SENIOR CITIZEN ASSOCIATION").grid(row=0,column=0,columnspan=5,sticky="n")
        ttk.Button(text="Add",command=self.add_member).grid(row=1,column=0,sticky="w")
        ttk.Button(text="Delete").grid(row=2,column=0,sticky="w")
        ttk.Button(text="Exit",command=lambda:self.parent.destroy()).grid(row=3,column=2,sticky="se")

        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")
        self.tree.heading("#3",text="Status",anchor="w")
        self.tree.grid(row=1,column=1,rowspan=2,columnspan=2,sticky="nsew")

    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):
        tk.Frame.__init__(self,child)
        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()
    Application(app)
    app.mainloop()
\$\endgroup\$
-2
\$\begingroup\$

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 :)

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to Code Review! Could you expand upon this? Perhaps explain what makes it easy to read... \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Oct 4 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.