【发布时间】:2020-08-07 07:35:16
【问题描述】:
我正在尝试在运行 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”,但没有其他内容(只是白色)。
【问题讨论】:
-
你能分享一些关于你的环境的信息吗?顺便说一句,使用
import *通常是个坏主意。 -
感谢您对 *.就我的环境而言,我不确定哪些信息有帮助,但我使用的是运行 Catalina OS 10.15.4 的 Mac。 Spyder 正在运行 python 3.7,IDLE 也是如此。但是,我的电脑上有两个 python 副本。 Spyder 正在使用一个而 IDLE 另一个。我找到了每个可执行文件的目录,并在单独的帖子中描述了这个问题,可以在 stackoverflow.com/questions/61395180/… 找到