So nun habe ich mir gedacht auch die Tasten (+,-,etc) wiederholen sich in ihrer Funktion und so müsste es wieder mit lambda funktionieren. Nur geht es nicht - liegt es am syntax oder ist es ein denkfehler ?
Code: Alles auswählen
# -*- coding: iso-8859-15 -*-
from Tkinter import *
class Rechner (Frame):
def __init__(self, master=None):
tastenlayout = [("7",3,7,1,10,0),("8",3,7,2,0,0),("9",3,7,3,10,0),("4",3,8,1,0,10),
("5",3,8,2,0,0),("6",3,8,3,0,0),("1",3,9,1,0,0),("2",3,9,2,0,0),
("3",3,9,3,0,0),("0",3,10,1,0,10),(",",3,10,3,0,0)]
funktastlayout = [("/",3,7,4,0,0),("X",3,8,4,0,0,),("-",3,9,4,0,0),("+",3,10,4,0,0)]
speicher=""
Frame.__init__(self, master,)
self.pack()
for text, width, row, column, padx, pady in tastenlayout:
self.tasten = Button(self, text=text,width=width, command=lambda t=text: self.ausgabe.insert(50,t))
self.tasten.grid(row=row, column=column, padx=padx, pady=pady)
for text, width, row, column, padx, pady in funktastlayout:
self.funktasten = Button(self, text=text,width=width, command=lambda speicher=speicher+self.ausgabe.get()+ text : self.ausgabe.delete(0,END))
self.funktasten.grid(row=row, column=column, padx=padx, pady=pady)
self.ausgabe = Entry(self,width=29,justify="right",)
self.ausgabe.grid(row=0, column=0,columnspan=6,pady=10)
root = Tk()
root.title('mudda`s Rechner 1.0')
root.config(cursor='crosshair')
Rechner(root).mainloop()