我的代码很简单,但是我收到了这个错误
Traceback (most recent call last): File "F:/Download/PY/Timer2.py", line 10, in e1.insert(0,"5") AttributeError: 'NoneType' object has no attribute 'insert'
import tkinter
from tkinter import *
root = tkinter.Tk()
root.title(string='prova')
root.configure(background='lightgray')
lbl_title = Label(root, padx=10, text="Timer", fg='black', bg='lightgray', font='Times 24', anchor='center').grid(row=0)
lbl_time = Label(root, font="Times 38", fg='black', bg='lightgray', width=8).grid(row=1)
e1 = Entry(root,font="Times 22", fg='black', bg='white', width=6).grid(row=2, column=0)
e1.insert(0,"5")
btn_start = Button(root, text='START', bg='black', fg='white', font='Times 24').grid(row=2, column=1)
root.mainloop()
如果您试图打印
e1
的值,您会发现它实际上是None
。这是因为您在定义了Entry
小部件并且grid()
返回None
之后使用了grid()
方法。所以,你需要把它们分开。这是工作代码。你知道吗另外,现在您应该意识到其他变量也是
None
。这是新的正确代码。你知道吗相关问题 更多 >
编程相关推荐