嗨,我正在尝试创建一个简单的触摸屏界面,允许用户在输入小部件中输入 4 位代码,然后将其保存为字符串。我不确定如何执行以下操作:当按下按钮将该值输入到 Entry 小部件时,这是我的代码,但我收到以下错误:
AttributeError:“NoneType”对象没有属性“插入”
def lockscreen():
locks = Toplevel(width=500,height=500)
locks.title('Lock Screen')
L1 = Label(locks,text="Enter 4 Digit Lock Code").grid(row=1,column=1,columnspan=3)
e1=Entry(locks, bd=5).grid(row=2,column=1,columnspan=3)
Button(locks, width=3, height=3, text='1', command =lambda:screen_text("1")).grid(row=3,column=1)
Button(locks, width=3, height=3, text='2').grid(row=3,column=2)
Button(locks, width=3, height=3, text='3').grid(row=3,column=3)
Button(locks, width=3, height=3, text='4').grid(row=4,column=1)
Button(locks, width=3, height=3, text='5').grid(row=4,column=2)
Button(locks, width=3, height=3, text='6').grid(row=4,column=3)
Button(locks, width=3, height=3, text='7').grid(row=5,column=1)
Button(locks, width=3, height=3, text='8').grid(row=5,column=2)
Button(locks, width=3, height=3, text='9').grid(row=5,column=3)
Button(locks, width=3, height=3, text='Close').grid(row=6,column=1)
Button(locks, width=3, height=3, text='0').grid(row=6,column=2)
Button(locks, width=3, height=3, text='Enter').grid(row=6,column=3)
def screen_text(text):
e1.insert(0,text)
return
master.mainloop()