我正在使用tkinter和python 3.6进行GUI,如何从textBox添加条目并将它们发送到另一个textBox? (总textBox)
def btntotal() :
Item2= var2.get()
Total = sum(Item2)
text2.insert(END, str(Total))
那不起作用。
答案 0 :(得分:0)
没有太多代码可以使用,但您应该能够适应这一点:
def btntotal() :
global Total # because you are modifying the variable Total in the function namespace
Item2 = float(var2.get()) # cast to float (or to int if you need ints)
Total += Item2 # update Total
text2.insert(END, str(Total)) # Display Total in text2
答案 1 :(得分:0)
如果两个Entry
小部件的值都是整数,则下面会将两个from tkinter import *
root = Tk()
def command():
try:
print(int(entry1.get())+int(entry2.get()))
except:
None
entry1 = Entry(root)
entry2 = Entry(root)
button = Button(root, text="Ok", command=command)
entry1.pack()
entry2.pack()
button.pack()
root.mainloop()
小部件的值相加:
componentDidMount