Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 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()
  184.  
  185.  
  186.  
  187.  
  188.  
  189. ---------------------------
  190.  
  191.  
  192.  
  193.  
  194.  
  195. import math
  196.  
  197. con = "Yes"
  198. while con == "Yes" or con == "yes" or con == "y":
  199.  
  200. a = float(input("Number 1: "))
  201.  
  202. b = float(input("Number 2: "))
  203.  
  204. opz = input("Operationszeichen (+ - * / //(Wurzel) **(Hoch)): ")
  205.  
  206. if (opz == "+", opz == "-", opz == "*", opz == "/", opz == "//", opz == "**"):
  207. if (opz == "//"):
  208. c = a // b
  209. print(c)
  210. con = input("Do you want to continue? Yes / No : ")
  211. if (opz == "**"):
  212. c = a ** b
  213. print(c)
  214. con = input("Do you want to continue? Yes / No : ")
  215. if (opz == "+"):
  216. c = a + b
  217. print(c)
  218. con = input("Do you want to continue? Yes / No : ")
  219. if (opz == "-"):
  220. c = a - b
  221. print(c)
  222. con = input("Do you want to continue? Yes / No : ")
  223. if (opz == "/"):
  224. if(b == 0):
  225. print("ERROR! You can't divide by zero.")
  226. con = input("Do you want to continue? Yes / No : ")
  227. else:
  228. c = a / b
  229. print(c)
  230. con = input("Do you want to continue? Yes / No : ")
  231. if (opz == "*"):
  232. c = a * b
  233. print(c)
  234. con = input("Do you want to continue? Yes / No : ")
  235. else:
  236. print("Operationszeichen nicht erkannt.")
  237. else:
  238. print("Calculator closed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement