from Tkinter import * def toList(text): a = text.splitlines() L = [] for i in a: s = "" z = True for j in i: #print j if j not in '+-*/': s += j z = True else: if s: L.append(s) if j: L.append(j) s = "" z = False if i[-1] in '+-*/': if z and j: L.append(j) else: if z and s: L.append(s) return L def Stack(i,s,S = None): if not S: S = [] if i == len(s): return S[0] a = s[i] if a.isdigit(): S.append(a) return Stack(s, S, i+1) else: c = S.pop() d = S.pop() S.append(Grundrechenarten(d,a,c)) return Stack(s, S, i+1) def Grundrechenarten(c,a,d): if a == '+': result = float(c)+float(d) elif a == '-': result = float(c)-float(d) elif a == '*': result = float(c)*float(d) elif a == '/': result = float(c)/float(d) if result == int(result): result = int(result) return result #----------------------------- def response(event): I = event.widget['text'] texts = UPN.text.get(1.0,END+'-1c') #print texts if I == 'DEL': UPN.text.delete(INSERT + '-1c',INSERT) elif I == 'Clear': UPN.text.delete(1.0,END) elif I == 'Enter': UPN.text.insert(INSERT,'\n') elif I == '=': s = toList(texts) #print s UPN.text.insert(END,'\n=\n') UPN.text.insert(END,f(s)) UPN.text.see('end') def UPN(): root.title('umgekehrte polnische Notation') root.geometry('400x500+200+100') UI = LabelFrame(root) UI.place(x = 1,y = 1,width = 398,height = 124) UPN.text = Text(UI) UPN.text.place(x=1,y=1,width=390,height=116) Li=[['7','8','9','+','DEL'], ['4','5','6','-','Enter'], ['1','2','3','*','='], ['0','00','.','/','Clear']] for i in range(len(Li[0])): for j in range(len(Li)): bt = Button(root) bt.place(x=(i+1)*60,y=120+(j+1)*60,width=50,height=50) bt['text'] = Li[j][i] bt.bind('',response,add=(root,)) def main(): UPN() root.mainloop() if __name__ == '__main__': root = Tk() main()