Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Tkinter
- from tkSimpleDialog import *
- root = Tkinter.Tk()
- root.title("Kalkulator")
- Label(root,text = "Kalkulator").grid(row=0, column =0, columnspan = 3)
- x = Entry(root, justify=Tkinter.RIGHT)
- x.grid(row=1, column=0, columnspan = 3)
- def zracunaj(y):
- c = d = 0
- g = h = dum = []
- znak = ["+", "-"]
- mrz = bu = 1
- b = y
- for i in znak:
- if i in y:
- y = y.replace(i, " ")
- a = y.split()
- if "+" and "-" in b:
- while c != -1:
- c = b.find("+", c + 1)
- g = g + [c]
- while d != -1:
- d = b.find("-", d + 1)
- h = h + [d]
- m = sorted(g + h)
- m = m[2:]
- for i in range(len(g) - 1):
- if g[i] in m:
- n = m.index(g[i])
- m.remove(g[i])
- m.insert(n, "g")
- for i in range(len(h) - 1):
- if h[i] in m:
- n = m.index(h[i])
- m.remove(h[i])
- m.insert(n, "h")
- for i in a:
- if len(i) >= 1:
- mu = i.split("*")
- for j in mu:
- if j.isdigit() is True:
- mrz *= int(j)
- else:
- kr = j.split("/")
- bu = int(kr[0])
- for i in range(1, len(kr)):
- bu = bu / int(kr[i])
- dum = dum + [mrz * bu]
- mrz = bu = 1
- bum = dum[0]
- if "+" and not "-" in b:
- for i in range(len(dum) - 1):
- bum = bum + dum[i + 1]
- elif "-" and not "+" in b:
- for i in range(len(dum) - 1):
- bum = bum - dum[i + 1]
- elif "+" and "-" in b:
- for i in range(len(dum) - 1):
- if m[i] == "h":
- bum = bum - dum[i + 1]
- elif m[i] == "g":
- bum = bum + dum[i + 1]
- bum =str(bum)
- x.insert(END, bum)
- def stevilo1():
- x.insert( END, "1")
- def stevilo2():
- x.insert(END, "2")
- def stevilo3():
- x.insert(END, "3")
- def stevilo4():
- x.insert(END, "4")
- def stevilo5():
- x.insert(END, "5")
- def stevilo6():
- x.insert(END, "6")
- def stevilo7():
- x.insert(END, "7")
- def stevilo8():
- x.insert(END, "8")
- def stevilo9():
- x.insert(END, "9")
- def stevilo0():
- x.insert(END, "0")
- def znakplus():
- x.insert(END, "+")
- def znakminus():
- x.insert(END, "-")
- def znakkrat():
- x.insert(END, "*")
- def znakdel():
- x.insert(END, "/")
- def znakje():
- x.insert(END, "=")
- y = Entry.get(x)
- y=y[:-1]
- zracunaj(y)
- def zbrisi():
- x.delete(0, END)
- Button(root, text = "1", command = stevilo1).grid(row=2, column=0, columnspan =1)
- Button(root, text = "2", command = stevilo2).grid(row=2, column=1, columnspan =1)
- Button(root, text = "3", command = stevilo3).grid(row=2, column=2, columnspan=1)
- Button(root, text = "4", command = stevilo4).grid(row=3, column=0, columnspan =1)
- Button(root, text = "5", command = stevilo5).grid(row=3, column=1, columnspan =1)
- Button(root, text = "6", command = stevilo6).grid(row=3, column=2, columnspan =1)
- Button(root, text = "7", command = stevilo7).grid(row=4, column=0, columnspan =1)
- Button(root, text = "8", command = stevilo8).grid(row=4, column=1, columnspan =1)
- Button(root, text = "9", command = stevilo9).grid(row=4, column=2, columnspan =1)
- Button(root, text = "0", command = stevilo0).grid(row=5, column=0, columnspan =1)
- Button(root, text = "+", command = znakplus).grid(row=5, column=1, columnspan =1)
- Button(root, text = "-", command = znakminus).grid(row=5, column=2,columnspan =1)
- Button(root, text = "*", command = znakkrat).grid(row=6, column=0,columnspan =1)
- Button(root, text = "/", command = znakdel).grid(row=6, column=1,columnspan =1)
- Button(root, text = "=", command = znakje).grid(row=6, column=2,columnspan =1)
- Button(root, text = "C", command = zbrisi).grid(row=7, column=0,columnspan =3)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement