muss bis Freitag für die Schule nen Taschenrechner fertigstellen.
Vorlage haben wir bekommen und erweitert.
Nur habe ich Probleme bei + - und = , wenn ich die button drücke erscheint einfach nur + - oder = ...
Aber ein Rechner muss ja rechnen können,bin schon soweit:
Code: Alles auswählen
from Tkinter import *
global anzeige
global masterstring
masterstring = " "
def Rechner (master):
global anzeige
frame = Frame(master)
frame.pack()
frame0 = Frame(frame)
frame0.pack(side=TOP)
frame1 = Frame(frame)
frame1.pack(side=TOP)
frame2 = Frame(frame)
frame2.pack(side=TOP)
frame3 = Frame(frame)
frame3.pack(side=TOP)
anzeige = Label(frame0, bg="#FFFFFF", bd=10, width=20,relief="sunken", anchor="e")
anzeige.pack(side=TOP)
B2 = Button(frame3, text="=", bg="green", width=5,command=gleich)
B2.pack(side=RIGHT)
B3 = Button(frame1, text="-", bg="blue", width=5,command=minus)
B3.pack(side=RIGHT)
B4 = Button(frame2, text="+", bg="red", width=5,command=plus)
B4.pack(side=RIGHT)
B5 = Button(frame1, text="7", bg="light yellow", width=5,command=sieben)
B5.pack(side=LEFT)
B6 = Button(frame1, text="8", bg="light yellow", width=5,command=acht)
B6.pack(side=LEFT)
B7 = Button(frame1, text="9", bg="light yellow", width=5,command=neun)
B7.pack(side=LEFT)
B9 = Button(frame2, text="4", bg="light yellow", width=5,command=vier)
B9.pack(side=LEFT)
B10 = Button(frame2, text="5", bg="light yellow", width=5,command=fuenf)
B10.pack(side=LEFT)
B11 = Button(frame2, text="6", bg="light yellow", width=5,command=sechs)
B11.pack(side=LEFT)
B13 = Button(frame3, text="1", bg="light yellow", width=5,command=eins)
B13.pack(side=LEFT)
B14 = Button(frame3, text="2", bg="light yellow", width=5,command=zwei)
B14.pack(side=LEFT)
B15 = Button(frame3, text="3", bg="light yellow", width=5,command=drei)
B15.pack(side=LEFT)
anzeige.configure(text= "Machen Sie eine Eingabe")
def gleich():
add_to_string('=')
def minus():
add_to_string('-')
def plus():
add_to_string('+')
def eins():
add_to_string('1')
def zwei():
add_to_string('2')
def drei():
add_to_string('3')
def vier():
add_to_string('4')
def fuenf():
add_to_string('5')
def sechs():
add_to_string('6')
def sieben():
add_to_string('7')
def acht():
add_to_string('8')
def neun():
add_to_string('9')
def add_to_string(pWert):
global masterstring
global anzeige
masterstring = masterstring + str(pWert)
anzeige.configure(text = masterstring)
print masterstring
root = Tk()
Rechner(root)
root.mainloop()