Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.66 KB | None | 0 0
  1. import math
  2. from tkinter import *
  3. #fenster aufbau
  4. root = Tk()
  5. root.title("Calculator")
  6.  
  7. #def controlls
  8. def awnser():
  9.     if "opz" in globals():
  10.         global e
  11.         e = 1
  12.         return
  13.     else:
  14.         global d
  15.         d = 1
  16.         return
  17. def awnser2():
  18.     if "opz" in globals():
  19.         global e
  20.         e = 2
  21.         return
  22.     else:
  23.         global d
  24.         d = 2
  25.         return
  26. def awnser3():
  27.     if "opz" in globals():
  28.         global e
  29.         e = 3
  30.         return
  31.     else:
  32.         global d
  33.         d = 3
  34.         return
  35. def awnser4():
  36.     if "opz" in globals():
  37.         global e
  38.         e = 4
  39.         return
  40.     else:
  41.         global d
  42.         d = 4
  43.         return
  44. def awnser5():
  45.     if "opz" in globals():
  46.         global e
  47.         e = 5
  48.         return
  49.     else:
  50.         global d
  51.         d = 5
  52.         return
  53. def awnser6():
  54.     if "opz" in globals():
  55.         global e
  56.         e = 6
  57.         return
  58.     else:
  59.         global d
  60.         d = 6
  61.         return
  62. def awnser7():
  63.     if "opz" in globals():
  64.         global e
  65.         e = 7
  66.         return
  67.     else:
  68.         global d
  69.         d = 7
  70.         return
  71. def awnser8():
  72.     if "opz" in globals():
  73.         global e
  74.         e = 8
  75.         return
  76.     else:
  77.         global d
  78.         d = 8
  79.         return
  80. def awnser9():
  81.     if "opz" in globals():
  82.         global e
  83.         e = 9
  84.         return
  85.     else:
  86.         global d
  87.         d = 9
  88.         return
  89. def awnser0():
  90.     if "opz" in globals():
  91.         global e
  92.         e = 0
  93.         return
  94.     else:
  95.         global d
  96.         d = 0
  97.         return
  98. def opzP():
  99.     global opz
  100.     opz = "+"
  101.     return
  102. def opzM():
  103.     global opz
  104.     opz = "-"
  105.     return
  106. def opzMA():
  107.     global opz
  108.     opz = "*"
  109.     return
  110. def opzG():
  111.     global opz
  112.     opz = "/"
  113.     return
  114. def btest1():
  115.     global e
  116.     e = 1
  117.     return
  118. def calcend():
  119.     if (opz == "+", opz == "-", opz == "*", opz == "/"):
  120.         if (opz == "+"):
  121.             c = d + e
  122.             c = str(c)
  123.             erg.set(c)
  124.         if (opz == "-"):
  125.             c = d - e
  126.             c = str(c)
  127.             erg.set(c)
  128.         if (opz == "/"):
  129.             if (e == 0):
  130.                 erg.set("MathError")
  131.             else:
  132.                 c = d / e
  133.                 c = str(c)
  134.                 erg.set(c)
  135.         if (opz == "*"):
  136.             c = d * e
  137.             c = str(c)
  138.             erg.set(c)
  139.     else:
  140.         print("Operationszeichen nicht erkannt.")
  141.  
  142. erg = StringVar()
  143. erg.set("Answer")
  144.  
  145. awn = Label(root, textvariable=erg,font="Impact")
  146.  
  147. #Was tut der Button
  148.  
  149. b1 = Button(root, text="1", command =awnser)
  150. b2 = Button(root, text="2", command =awnser2)
  151. b3 = Button(root, text="3", command =awnser3)
  152. b4 = Button(root, text="4", command =awnser4)
  153. b5 = Button(root, text="5", command =awnser5)
  154. b6 = Button(root, text="6", command =awnser6)
  155. b7 = Button(root, text="7", command =awnser7)
  156. b8 = Button(root, text="8", command =awnser8)
  157. b9 = Button(root, text="9", command =awnser9)
  158. b0 = Button(root, text="0", command =awnser0)
  159. bP = Button(root, text="+", command =opzP)
  160. bM = Button(root, text="-", command =opzM)
  161. bMA = Button(root, text="*", command =opzMA)
  162. bG = Button(root, text="/", command =opzG)
  163. calcend = Button(root, text="calculate", command =calcend)
  164.  
  165. # Zeige die Sachen im Fenster
  166. awn.pack()
  167. b1.pack(side=LEFT)
  168. b2.pack(side=LEFT)
  169. b3.pack(side=LEFT)
  170. b4.pack(side=LEFT)
  171. b5.pack(side=LEFT)
  172. b0.pack(side=RIGHT)
  173. b9.pack(side=RIGHT)
  174. b8.pack(side=RIGHT)
  175. b7.pack(side=RIGHT)
  176. b6.pack(side=RIGHT)
  177. calcend.pack(side=BOTTOM)
  178. bP.pack(side=BOTTOM)
  179. bM.pack(side=BOTTOM)
  180. bMA.pack(side=BOTTOM)
  181. bG.pack(side=BOTTOM)
  182.  
  183. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement