def addstudents(stuid,stuname,stusex,stuaddress,china,math,english): sqlstr="""insert into students(stuid,stuname,stusex,stuaddress,china,math,english) values(?,?,?,?,?,?,?)""" cursor.execute(sqlstr,(stuid,stuname,stusex,stuaddress,china,math,english)) cursor.commit() return stuid,stuname,stusex,stuaddress,china,math,english #添加学生信息的窗口 def windowadd(): window=tkinter.Toplevel() window.title("添加学生信息")#窗口名字 window.geometry("600x500")#窗口大小 #学号的标签和entry sid=tkinter.StringVar() sid.set("") lable1=tkinter.Label(window,text="学 号:",font=(20),width=25) lable1.place(x=40,y=50,anchor='nw') input1=tkinter.Entry(window,show=None,font=(20),textvariable=sid,width=25) input1.place(x=200,y=50,anchor='nw') sname=tkinter.StringVar() sname.set("") lable2=tkinter.Label(window,text="姓 名:",font=(20),width=25) lable2.place(x=40,y=100,anchor='nw') input2=tkinter.Entry(window,show=None,font=(20),textvariable=sname,width=25) input2.place(x=200, y=100, anchor='nw') ssex=tkinter.StringVar() ssex.set("") lable3=tkinter.Label(window,text="性 别:",font=(20),width=25) lable3.place(x=40,y=150,anchor='nw') input3=tkinter.Entry(window,show=None,font=(20),textvariable=ssex,width=25) input3.place(x=200, y=150, anchor='nw') saddress=tkinter.StringVar() saddress.set("") lable4=tkinter.Label(window,text="地 址:",font=(20),width=25) lable4.place(x=40,y=200,anchor='nw') input4=tkinter.Entry(window,show=None,font=(20),textvariable=saddress,width=25) input4.place(x=200, y=200, anchor='nw') schina=tkinter.StringVar() schina.set("") lable5=tkinter.Label(window,text="语 文:",font=(20),width=25) lable5.place(x=40,y=250,anchor='nw') input5=tkinter.Entry(window,show=None,font=(20),textvariable=schina,width=25) input5.place(x=200, y=250, anchor='nw') smath=tkinter.StringVar() smath.set("") lable6=tkinter.Label(window,text="数 学:",font=(20),width=25) lable6.place(x=40,y=300,anchor='nw') input6=tkinter.Entry(window,show=None,font=(20),textvariable=smath,width=25) input6.place(x=200, y=300, anchor='nw') seng=tkinter.StringVar() seng.set("") lable7=tkinter.Label(window,text="英 语:",font=(20),width=25) lable7.place(x=40,y=350,anchor='nw') input7=tkinter.Entry(window,show=None,font=(23),textvariable=seng,width=25) input7.place(x=200, y=350, anchor='nw') b_yes=tkinter.Button(window,text='确认',bg='blue',font=(20),command=lambda:addstudents(sid.get(),sname.get(),ssex.get(),saddress.get(),schina.get(),smath.get(),seng.get())) b_yes.place(x=70,y=420,anchor='nw') b_no=tkinter.Button(window,text="取消",bg='blue',font=(23),command=lambda :window.destroy()) b_no.place(x=400,y=420,anchor='nw') window.mainloop() 为什么会有 File "D:\pythonProject2\main.py", line 119, in <lambda> b_yes=tkinter.Button(window,text='确认',bg='blue',font=(20),command=lambda:addstudents(sid.get(),sname.get(),ssex.get(),saddress.get(),schina.get(),smath. TypeError: 'Button' object is not callable的错误
时间: 2024-01-07 10:04:24 浏览: 176
MySQL自学文档第三周
这个错误通常是因为你的Button对象名字和函数名相同所导致的,即你的Button名字是"addstudents",而你的函数名也是"addstudents"。在你的代码中,当你点击Button时,它会试图调用名为"addstudents"的Button对象,而不是调用你定义的函数。为了解决这个问题,你需要将Button的对象名修改为另一个不同的名字,比如'b_yes',这样就不会与函数名冲突了。
阅读全文