Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from tkinter import *
- #fenster aufbau
- root = Tk()
- root.title("Calculator")
- #def controlls
- def awnser():
- if "opz" in globals():
- global e
- e = 1
- return
- else:
- global d
- d = 1
- return
- def awnser2():
- if "opz" in globals():
- global e
- e = 2
- return
- else:
- global d
- d = 2
- return
- def awnser3():
- if "opz" in globals():
- global e
- e = 3
- return
- else:
- global d
- d = 3
- return
- def awnser4():
- if "opz" in globals():
- global e
- e = 4
- return
- else:
- global d
- d = 4
- return
- def awnser5():
- if "opz" in globals():
- global e
- e = 5
- return
- else:
- global d
- d = 5
- return
- def awnser6():
- if "opz" in globals():
- global e
- e = 6
- return
- else:
- global d
- d = 6
- return
- def awnser7():
- if "opz" in globals():
- global e
- e = 7
- return
- else:
- global d
- d = 7
- return
- def awnser8():
- if "opz" in globals():
- global e
- e = 8
- return
- else:
- global d
- d = 8
- return
- def awnser9():
- if "opz" in globals():
- global e
- e = 9
- return
- else:
- global d
- d = 9
- return
- def awnser0():
- if "opz" in globals():
- global e
- e = 0
- return
- else:
- global d
- d = 0
- return
- def opzP():
- global opz
- opz = "+"
- return
- def opzM():
- global opz
- opz = "-"
- return
- def opzMA():
- global opz
- opz = "*"
- return
- def opzG():
- global opz
- opz = "/"
- return
- def btest1():
- global e
- e = 1
- return
- def calcend():
- if (opz == "+", opz == "-", opz == "*", opz == "/"):
- if (opz == "+"):
- c = d + e
- c = str(c)
- erg.set(c)
- if (opz == "-"):
- c = d - e
- c = str(c)
- erg.set(c)
- if (opz == "/"):
- if (e == 0):
- erg.set("MathError")
- else:
- c = d / e
- c = str(c)
- erg.set(c)
- if (opz == "*"):
- c = d * e
- c = str(c)
- erg.set(c)
- else:
- print("Operationszeichen nicht erkannt.")
- erg = StringVar()
- erg.set("Answer")
- awn = Label(root, textvariable=erg,font="Impact")
- #Was tut der Button
- b1 = Button(root, text="1", command =awnser)
- b2 = Button(root, text="2", command =awnser2)
- b3 = Button(root, text="3", command =awnser3)
- b4 = Button(root, text="4", command =awnser4)
- b5 = Button(root, text="5", command =awnser5)
- b6 = Button(root, text="6", command =awnser6)
- b7 = Button(root, text="7", command =awnser7)
- b8 = Button(root, text="8", command =awnser8)
- b9 = Button(root, text="9", command =awnser9)
- b0 = Button(root, text="0", command =awnser0)
- bP = Button(root, text="+", command =opzP)
- bM = Button(root, text="-", command =opzM)
- bMA = Button(root, text="*", command =opzMA)
- bG = Button(root, text="/", command =opzG)
- calcend = Button(root, text="calculate", command =calcend)
- # Zeige die Sachen im Fenster
- awn.pack()
- b1.pack(side=LEFT)
- b2.pack(side=LEFT)
- b3.pack(side=LEFT)
- b4.pack(side=LEFT)
- b5.pack(side=LEFT)
- b0.pack(side=RIGHT)
- b9.pack(side=RIGHT)
- b8.pack(side=RIGHT)
- b7.pack(side=RIGHT)
- b6.pack(side=RIGHT)
- calcend.pack(side=BOTTOM)
- bP.pack(side=BOTTOM)
- bM.pack(side=BOTTOM)
- bMA.pack(side=BOTTOM)
- bG.pack(side=BOTTOM)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement