import tkinter
from tkinter import *
from tkinter import messagebox
c = tkinter.Tk()
c.geometry("350x500+300+300")
#c.resizable(0,0)
c.title("Calculator")
v=""
A=0
operator=""
def bt1_clicked():
global v
v=v+"7"
data.set(v)
def bt2_clicked():
global v
v=v+"8"
data.set(v)
def bt3_clicked():
global v
v=v+"9"
data.set(v)
def bt4_clicked():
global A
global operator
global v
A=int(v)
operator="+"
v=v+"+"
data.set(v)
def bt5_clicked():
global v
v=v+"4"
data.set(v)
def bt6_clicked():
global v
v=v+"5"
data.set(v)
def bt7_clicked():
global v
v=v+"6"
data.set(v)
def bt8_clicked():
global A
global operator
global v
A=int(v)
operator="-"
v=v+"-"
data.set(v)
def bt9_clicked():
global v
v=v+"1"
data.set(v)
def bt10_clicked():
global v
v=v+"2"
data.set(v)
def bt11_clicked():
global v
v=v+"3"
data.set(v)
def bt12_clicked():
global A
global operator
global v
A=int(v)
operator="x"
v=v+"x"
data.set(v)
def bt13_clicked():
global A
global operator
global v
v=""
A=0
operator=""
data.set(v)
def bt14_clicked():
global v
v=v+"0"
data.set(v)
def bt15_clicked():
global A
global operator
global v
A=int(v)
operator="÷"
v=v+"÷"
data.set(v)
def bt16_clicked():
global A
global operator
global v
v1=v
if operator=="+":
B=int((v1.split("+")[1]))
R=A+B
data.set(R)
v=str(R)
elif operator=="-":
B=int((v1.split("-")[1]))
R=A-B
data.set(R)
v=str(R)
elif operator=="x":
B=int((v1.split("x")[1]))
R=A*B
data.set(R)
v=str(R)
elif operator=="÷":
B=int((v1.split("÷")[1]))
if B==0:
messagebox.showerror("Error","∞")
A=""
v=""
data.set(v)
else:
R=A/B
data.set(R)
v=str(R)
data=StringVar()
l=Label(c,text="Label",anchor=SE,font=("Arial",20),textvariable=data,bg="black",fg="grey")
l.pack(expand=True, fill="both")
br1=Frame(c)
br1.pack(expand=True, fill="both")
br2=Frame(c)
br2.pack(expand=True, fill="both")
br3=Frame(c)
br3.pack(expand=True, fill="both")
br4=Frame(c)
br4.pack(expand=True, fill="both")
bt1=Button(br1,text=" 7",font=("Arial",22),relief=GROOVE,command=bt1_clicked,bg="grey",fg="black")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br1,text="8 ",font=("Arial",22),relief=GROOVE,command=bt2_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br1,text=" 9",font=("Arial",22),relief=GROOVE,command=bt3_clicked,bg="grey",fg="black")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br1,text="+",font=("Arial",22),relief=GROOVE,command=bt4_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
bt1=Button(br2,text=" 4",font=("Arial",22),relief=GROOVE,command=bt5_clicked,bg="grey",fg="black")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br2,text="5 ",font=("Arial",22),relief=GROOVE,command=bt6_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br2,text=" 6",font=("Arial",22),relief=GROOVE,command=bt7_clicked,bg="grey",fg="black")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br2,text=" -",font=("Arial",22),relief=GROOVE,command=bt8_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
bt1=Button(br3,text=" 1",font=("Arial",22),relief=GROOVE,command=bt9_clicked,bg="grey",fg="black")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br3,text=" 2",font=("Arial",22),relief=GROOVE,command=bt10_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br3,text=" 3",font=("Arial",22),relief=GROOVE,command=bt11_clicked,bg="grey",fg="black")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br3,text=" x",font=("Arial",22),relief=GROOVE,command=bt12_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
bt1=Button(br4,text="C",font=("Arial",22),relief=GROOVE,command=bt13_clicked,border=5,bg="black",fg="grey")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br4,text="0 ",font=("Arial",22),relief=GROOVE,command=bt14_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br4,text="÷ ",font=("Arial",22),relief=GROOVE,command=bt15_clicked,border=5,bg="black",fg="grey")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br4,text=" =",font=("Arial",22),relief=GROOVE,command=bt16_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
c.mainloop()
from tkinter import *
from tkinter import messagebox
c = tkinter.Tk()
c.geometry("350x500+300+300")
#c.resizable(0,0)
c.title("Calculator")
v=""
A=0
operator=""
def bt1_clicked():
global v
v=v+"7"
data.set(v)
def bt2_clicked():
global v
v=v+"8"
data.set(v)
def bt3_clicked():
global v
v=v+"9"
data.set(v)
def bt4_clicked():
global A
global operator
global v
A=int(v)
operator="+"
v=v+"+"
data.set(v)
def bt5_clicked():
global v
v=v+"4"
data.set(v)
def bt6_clicked():
global v
v=v+"5"
data.set(v)
def bt7_clicked():
global v
v=v+"6"
data.set(v)
def bt8_clicked():
global A
global operator
global v
A=int(v)
operator="-"
v=v+"-"
data.set(v)
def bt9_clicked():
global v
v=v+"1"
data.set(v)
def bt10_clicked():
global v
v=v+"2"
data.set(v)
def bt11_clicked():
global v
v=v+"3"
data.set(v)
def bt12_clicked():
global A
global operator
global v
A=int(v)
operator="x"
v=v+"x"
data.set(v)
def bt13_clicked():
global A
global operator
global v
v=""
A=0
operator=""
data.set(v)
def bt14_clicked():
global v
v=v+"0"
data.set(v)
def bt15_clicked():
global A
global operator
global v
A=int(v)
operator="÷"
v=v+"÷"
data.set(v)
def bt16_clicked():
global A
global operator
global v
v1=v
if operator=="+":
B=int((v1.split("+")[1]))
R=A+B
data.set(R)
v=str(R)
elif operator=="-":
B=int((v1.split("-")[1]))
R=A-B
data.set(R)
v=str(R)
elif operator=="x":
B=int((v1.split("x")[1]))
R=A*B
data.set(R)
v=str(R)
elif operator=="÷":
B=int((v1.split("÷")[1]))
if B==0:
messagebox.showerror("Error","∞")
A=""
v=""
data.set(v)
else:
R=A/B
data.set(R)
v=str(R)
data=StringVar()
l=Label(c,text="Label",anchor=SE,font=("Arial",20),textvariable=data,bg="black",fg="grey")
l.pack(expand=True, fill="both")
br1=Frame(c)
br1.pack(expand=True, fill="both")
br2=Frame(c)
br2.pack(expand=True, fill="both")
br3=Frame(c)
br3.pack(expand=True, fill="both")
br4=Frame(c)
br4.pack(expand=True, fill="both")
bt1=Button(br1,text=" 7",font=("Arial",22),relief=GROOVE,command=bt1_clicked,bg="grey",fg="black")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br1,text="8 ",font=("Arial",22),relief=GROOVE,command=bt2_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br1,text=" 9",font=("Arial",22),relief=GROOVE,command=bt3_clicked,bg="grey",fg="black")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br1,text="+",font=("Arial",22),relief=GROOVE,command=bt4_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
bt1=Button(br2,text=" 4",font=("Arial",22),relief=GROOVE,command=bt5_clicked,bg="grey",fg="black")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br2,text="5 ",font=("Arial",22),relief=GROOVE,command=bt6_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br2,text=" 6",font=("Arial",22),relief=GROOVE,command=bt7_clicked,bg="grey",fg="black")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br2,text=" -",font=("Arial",22),relief=GROOVE,command=bt8_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
bt1=Button(br3,text=" 1",font=("Arial",22),relief=GROOVE,command=bt9_clicked,bg="grey",fg="black")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br3,text=" 2",font=("Arial",22),relief=GROOVE,command=bt10_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br3,text=" 3",font=("Arial",22),relief=GROOVE,command=bt11_clicked,bg="grey",fg="black")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br3,text=" x",font=("Arial",22),relief=GROOVE,command=bt12_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
bt1=Button(br4,text="C",font=("Arial",22),relief=GROOVE,command=bt13_clicked,border=5,bg="black",fg="grey")
bt1.pack(side=LEFT,expand=True,fill="both")
bt2=Button(br4,text="0 ",font=("Arial",22),relief=GROOVE,command=bt14_clicked,bg="grey",fg="black")
bt2.pack(side=LEFT,expand=True,fill="both")
bt3=Button(br4,text="÷ ",font=("Arial",22),relief=GROOVE,command=bt15_clicked,border=5,bg="black",fg="grey")
bt3.pack(side=LEFT,expand=True,fill="both")
bt4=Button(br4,text=" =",font=("Arial",22),relief=GROOVE,command=bt16_clicked,border=5,bg="black",fg="grey")
bt4.pack(side=LEFT,expand=True,fill="both")
c.mainloop()