I know this is stupid but how do i add a quit button?

from tkinter import *

from tkinter.font import Font



def button(frame, text, command=None):

    ft = Font(family=('Verdana'), size=14)

    return Button(frame, text=text, font=ft, width=3, command=command)



def frame(frame, side=LEFT, bg="black"):

    f = Frame(frame, background=bg, padx=5, pady=5)

    f.pack(side=side, expand=YES, fill=BOTH)

    return f



class App:

    def __init__(self, tk):

        ft = Font(family=('Verdana'), size=14)

        main = frame(tk)



        l_frame = frame(main)

        r_frame = frame(main)

        calc_frame = frame(l_frame)



        self.input = Entry(calc_frame, font=ft, width=15, background="white")

        self.input.pack(side=TOP)



        self.btn_frame = frame(calc_frame)



        x, y = 0, 0

        for key in ("()%C", "+-*/", "1234", "5678", "90.="):

            for c in key:

                if c == "=":

                    btn = button(self.btn_frame, c, self.equalAction)

                elif c == "C":

                    btn = button(self.btn_frame, c, self.cleanAction)

                else:

                    btn = button(self.btn_frame, c, lambda i=c: self.input.insert(INSERT, i))



                btn.grid(row=x, column=y)

                y += 1



            x += 1

            y = 0



        self.log = Text(r_frame, font=Font(family=('Verdana'), size=10), width=25, height=14, background="yellow")

        self.log.pack(side=RIGHT)



    def cleanAction(self):

        self.input.delete(0, END)

    def equalAction(self):

        tmp = self.input.get()

        try:

            result = tmp + "=" + str(eval(tmp))

            self.log.insert(1.0, result + "\n");

            print(result)

        except Exception:

            self.log.insert(1.0, "Wrong expression\n");


if __name__ == '__main__':

    root = Tk()

    root.title("Calculator")

    root.geometry()

    app = App(root)

    root.mainloop()

Try

        self.btnquit = button(calc_frame, "Quit", tk.destroy)
        self.btnquit.pack(side = LEFT)

in method init, before self.input = ....

invalid syntax

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.