我正在尝试在运行 python 3.7 的 Spyder 3.32 中使用 tkinter。我有一个简单的脚本来接受两个数字并打印它们的总和:
from tkinter import *
window = Tk()
window.title("Sum Calculator")
window.geometry('600x300')
lbl1 = Label(window, text="First Number")
lbl1.grid(row=0,column=0)
txt1 = Entry(window,width=10)
txt1.grid(row=0,column=1)
lbl2 = Label(window, text="Second Number")
lbl2.grid(row=1,column=0)
txt2 = Entry(window,width=10)
txt2.grid(row=1,column=1)
lbl_sum=Label(window, text="Sum:")
lbl_sum.grid(row=2,column=0)
def clicked():
res="Sum= "+str(float(txt1.get())+float(txt2.get()))
lbl_sum.configure(text= res)
btn = Button(window, text="Compute", command=clicked)
btn.grid(row=3,column=0)
window.mainloop()
这在 IDLE 中工作得非常好,但是当在 Spyder 中运行时,我得到的只是一个标题正确的窗口,“Sum Calculator”,但没有别的(只是白色)。