我正在尝试使用tkinter提交表单提交。但是我遇到一个错误,指出'NoneType'对象没有属性'get'。我不知道为什么会发生这种情况。
// Create an event listener for deleted messages
client.on('messageDelete', message => {
// Fetch the designated channel on a server
const channel = message.guild.channels.cache.find(ch => ch.name === 'deleted-messages-log');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send a message in the log channel
channel.send(`A message has been deleted. The message was: ${message.content}`);
});
错误如下所示
def onsubmit():
email=email_entry.get()
myconn = mysql.connector.connect(host = "localhost", user = "root",password =
"",database="project")
cur = myconn.cursor()
sql1="INSERT INTO
register(name,email,gender,qualification,courses,username,password)values(%s,%s,%s,%s,%s,%s,%s)"
values=[(name,email,gender,qualification,check_list,username,password)]
cur.executemany(sql1,values)
myconn.commit()
myconn .close()
global email_in
lemail=Label(root,text="Email",width=20,font=("bold",10)).place(x=80,y=180)
email_entry=Entry(root).place(x=240,y=180)
sub=Button(root,text="Submit",bg='brown',fg='white',width=20,command=onsubmit).place(x=160,y=480)
root.mainloop()
答案 0 :(得分:2)
问题非常简单,而不是在同一行中说place()
,而是说:
email_entry=Entry(root)
email_entry.place(x=240,y=180)
现在,所有问题都将得到解决。
这是因为email_entry=Entry(root).place(x=240,y=180)
返回None
,即,当您使用email_entry.get()
时,您说的是email_entry=Entry(root).place(x=240,y=180).get()
,因为{{1} }是email_entry=Entry(root).place(x=240,y=180)
,他们收到了错误消息。
其他修正:
None
,因为它在那里没有用。global
应该是列表中的元组而不是元组,因此请将其更改为values
欢呼
答案 1 :(得分:0)
创建变量email_txt = StringVar()
将此email_entry=Entry(root).place(x=240,y=180)
修改为
email_entry=Entry(root, textvariable=email_txt).place(x=240,y=180)
在功能中,修改
email=email_entry.get()
至email=email_txt.get()