0

我知道有一个类似的问题,但我认为答案不适用于我的代码,我想知道答案。由于这个问题,我的程序的某些方面将无法工作。这是我的代码:

from tkinter import *

def Add():
    num = entry_box.get()
    num1 = entry_box1.get()
    total = int(num) + int(num1)
    button["bg"] = "blue"
    button["fg"] = "white"
    entry_box.delete(0, END)
    entry_box1.delete(0, END)
    entry_box1.insert(0,total)

def Reset():
    button1["bg"] = "blue"
    button1["fg"] = "white"
    entry_box.delete(0, END)
    entry_box1.delete(0, END)

window = Tk()
window.geometry("200x150")

label = Message(text = "Enter the number you would like to add to the total: ")
label.pack()

entry_box = Entry(text = 0)
entry_box.pack()

num = entry_box.get()

entry_box1 = Entry(text = "0")
entry_box1.insert(0,"0")
entry_box1.pack()

num1 = entry_box.get()

button = Button(text = "Add", command = Add)
button.pack()

button1 = Button(text = "Reset", command = Reset)
button1.pack()

window.mainloop()
4

1 回答 1

0

这是导致问题text的小部件的参数。 据我所知,小部件没有这样的参数。 所以去掉参数会让你的程序按预期运行。Entry
Entry
text

entry_box = Entry(text = 0)
entry_box1 = Entry(text = "0")

# to simply

entry_box = Entry()
entry_box1 = Entry()
于 2020-04-19T15:53:22.710 回答