所以我试图在python中学习tkinter,我发现这个代码在网上没有用,我一直在搞乱它,改变布局等等,但我不能让数学或清除按钮工作,如果有人可以告诉我为什么以及如何解决它,我将非常感激。
#import tkinter
from tkinter import *
root = Tk()
root.title("Calculator")
Entrybox = Entry(root)
#set the coordinates for the entry box(columnspan is large as it was the only way to fit the "7" in the corner)
Entrybox.grid(row=1, column=0, columnspan=42)
#defines what the button does
def inputzero():
old_value = Entrybox.get()
new_value = old_value + "0"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
#defines where the button is and how looks
one = Button (root, text="0", command = inputzero, width = 3)
one.grid (row = 9, column = 0,)
def inputone():
old_value = Entrybox.get()
new_value = old_value + "1"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
one = Button (root, text="1", command = inputone, width = 3)
one.grid (row = 8, column = 0, columnspan=1)
def inputtwo():
old_value = Entrybox.get()
new_value = old_value + "2"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
two = Button(root, text="2", command = inputtwo, width= 3)
two.grid (row = 8, column = 1)
def inputthree():
old_value = Entrybox.get()
new_value = old_value + "3"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
three = Button (root, text="3", command = inputthree, width= 3)
three.grid (row = 8, column = 2)
def inputfour():
old_value = Entrybox.get()
new_value = old_value + "4"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
four = Button (root, text="4", command = inputfour, width =3)
four.grid (row = 7, column = 0)
def inputfive():
old_value = Entrybox.get()
new_value = old_value + "5"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
five = Button (root, text="5", command = inputfive, width = 3)
five.grid (row = 7, column = 1)
def inputsix():
old_value = Entrybox.get()
new_value = old_value + "6"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
six = Button (root, text="6", command = inputsix, width = 3)
six.grid (row = 7, column =2)
def inputseven():
old_value = Entrybox.get()
new_value = old_value + "7"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
seven = Button (root, text="7", command = inputseven, width = 3 )
seven.grid (row = 6, column = 0)
def inputeight():
old_value = Entrybox.get()
new_value = old_value + "8"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
eight = Button (root, text="8", command = inputeight, width = 3)
eight.grid (row = 6, column = 1)
def inputnine():
old_value = Entrybox.get()
new_value = old_value + "9"
Entrybox.delete(0, END)
Entrybox.insert(0, new_value)
nine = Button (root, text="9", command = inputnine, width = 3)
nine.grid (row = 6, column = 2)
def inputadd():
y = Entrybox.get()
Entrybox_value = Entrybox.get()
Entrybox.delete(0, END)
Entrybox.insert(0, "+")
add = Button (root, text="+", foreground="Blue", command = inputadd, width=3)
add.grid (row = 9, column = 1)
def inputsubtract():
x= Entrybox.get ()
Entrybox_value = Entrybox.get
Entrybox.delete(0, END)
Entrybox.insert (0, "-")
subtract = Button (root, text="-", foreground="blue", command = inputsubtract, width=3)
subtract.grid (row= 9, column = 2)
#defines the equals button and what it does on input
def inputequals () :
z = inputadd
x+y
if z == inputsubtract:
x-y
y= Entrybox.get ()
Entrybox_value = Entrybox.get
Entrybox.delete (0, END)
Entrybox.insert (0, z)
equals = Button (root, text="=", command = inputequals, foreground="Green", width =5, height=0)
equals.grid (row=9, column = 3)
def clear():
EntryBox.delete(0, END)
EntryBox.insert(0, '0')
clear = Button (root,text="Clr")
clear.grid (row=8, column = 3)
root.mainloop()