Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. import Tkinter
  2. from tkSimpleDialog import *
  3.  
  4.  
  5. root = Tkinter.Tk()
  6. root.title("Kalkulator")
  7. Label(root,text = "Kalkulator").grid(row=0, column =0, columnspan = 3)
  8.  
  9. x = Entry(root, justify=Tkinter.RIGHT)
  10. x.grid(row=1, column=0, columnspan = 3)
  11.  
  12. def zracunaj(y):
  13. c = d = 0
  14. g = h = dum = []
  15. znak = ["+", "-"]
  16. mrz = bu = 1
  17. b = y
  18. for i in znak:
  19. if i in y:
  20. y = y.replace(i, " ")
  21. a = y.split()
  22.  
  23. if "+" and "-" in b:
  24. while c != -1:
  25. c = b.find("+", c + 1)
  26. g = g + [c]
  27. while d != -1:
  28. d = b.find("-", d + 1)
  29. h = h + [d]
  30. m = sorted(g + h)
  31. m = m[2:]
  32. for i in range(len(g) - 1):
  33. if g[i] in m:
  34. n = m.index(g[i])
  35. m.remove(g[i])
  36. m.insert(n, "g")
  37. for i in range(len(h) - 1):
  38. if h[i] in m:
  39. n = m.index(h[i])
  40. m.remove(h[i])
  41. m.insert(n, "h")
  42. for i in a:
  43. if len(i) >= 1:
  44. mu = i.split("*")
  45. for j in mu:
  46. if j.isdigit() is True:
  47. mrz *= int(j)
  48. else:
  49. kr = j.split("/")
  50. bu = int(kr[0])
  51. for i in range(1, len(kr)):
  52. bu = bu / int(kr[i])
  53.  
  54. dum = dum + [mrz * bu]
  55. mrz = bu = 1
  56. bum = dum[0]
  57. if "+" and not "-" in b:
  58. for i in range(len(dum) - 1):
  59. bum = bum + dum[i + 1]
  60. elif "-" and not "+" in b:
  61. for i in range(len(dum) - 1):
  62. bum = bum - dum[i + 1]
  63.  
  64. elif "+" and "-" in b:
  65. for i in range(len(dum) - 1):
  66. if m[i] == "h":
  67. bum = bum - dum[i + 1]
  68. elif m[i] == "g":
  69. bum = bum + dum[i + 1]
  70. bum =str(bum)
  71. x.insert(END, bum)
  72.  
  73. def stevilo1():
  74. x.insert( END, "1")
  75. def stevilo2():
  76. x.insert(END, "2")
  77. def stevilo3():
  78. x.insert(END, "3")
  79. def stevilo4():
  80. x.insert(END, "4")
  81. def stevilo5():
  82. x.insert(END, "5")
  83. def stevilo6():
  84. x.insert(END, "6")
  85. def stevilo7():
  86. x.insert(END, "7")
  87. def stevilo8():
  88. x.insert(END, "8")
  89. def stevilo9():
  90. x.insert(END, "9")
  91. def stevilo0():
  92. x.insert(END, "0")
  93. def znakplus():
  94. x.insert(END, "+")
  95. def znakminus():
  96. x.insert(END, "-")
  97. def znakkrat():
  98. x.insert(END, "*")
  99. def znakdel():
  100. x.insert(END, "/")
  101. def znakje():
  102. x.insert(END, "=")
  103. y = Entry.get(x)
  104. y=y[:-1]
  105. zracunaj(y)
  106.  
  107. def zbrisi():
  108. x.delete(0, END)
  109.  
  110.  
  111. Button(root, text = "1", command = stevilo1).grid(row=2, column=0, columnspan =1)
  112. Button(root, text = "2", command = stevilo2).grid(row=2, column=1, columnspan =1)
  113. Button(root, text = "3", command = stevilo3).grid(row=2, column=2, columnspan=1)
  114. Button(root, text = "4", command = stevilo4).grid(row=3, column=0, columnspan =1)
  115. Button(root, text = "5", command = stevilo5).grid(row=3, column=1, columnspan =1)
  116. Button(root, text = "6", command = stevilo6).grid(row=3, column=2, columnspan =1)
  117. Button(root, text = "7", command = stevilo7).grid(row=4, column=0, columnspan =1)
  118. Button(root, text = "8", command = stevilo8).grid(row=4, column=1, columnspan =1)
  119. Button(root, text = "9", command = stevilo9).grid(row=4, column=2, columnspan =1)
  120. Button(root, text = "0", command = stevilo0).grid(row=5, column=0, columnspan =1)
  121. Button(root, text = "+", command = znakplus).grid(row=5, column=1, columnspan =1)
  122. Button(root, text = "-", command = znakminus).grid(row=5, column=2,columnspan =1)
  123. Button(root, text = "*", command = znakkrat).grid(row=6, column=0,columnspan =1)
  124. Button(root, text = "/", command = znakdel).grid(row=6, column=1,columnspan =1)
  125. Button(root, text = "=", command = znakje).grid(row=6, column=2,columnspan =1)
  126. Button(root, text = "C", command = zbrisi).grid(row=7, column=0,columnspan =3)
  127.  
  128. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement