def xinxi():
menu.withdraw()
single=tk.Tk()
single.title("个人信息")
single.geometry("600x600")
name_lable = tk.Label(single,text="姓名:",font=(12))
name_lable.place(x=150, y=80, width=50, height=20)
ent_name = tk.StringVar()
tk.Entry(single,width=20,textvariable=ent_name).place(x=200, y=80, width=150, height=20)
'''ent_name = tk.Entry(single,textvariable = tk.StringVar(),font = 12)
ent_name.place(x=200, y=80, width=150, height=20)'''
sex_lable = tk.Label(single,text="性别:",font=(12))
sex_lable.place(x=150, y=120, width=50, height=20)
ent_sex = tk.StringVar()
tk.Entry(single,width=20,textvariable=ent_sex).place(x=200, y=120, width=150, height=20)
'''ent_sex = tk.Entry(single,textvariable = tk.StringVar(),font = 12)
ent_sex.place(x=200, y=120, width=150, height=20)'''
age_lable = tk.Label(single,text="年龄:",font=(12))
age_lable.place(x=150, y=160, width=50, height=20)
ent_age = tk.StringVar()
tk.Entry(single,width=20,textvariable=ent_age).place(x=200, y=160, width=150, height=20)
'''ent_age = tk.Entry(single,textvariable = tk.StringVar(),font = (12))
ent_age.place(x=200, y=160, width=150, height=20)'''
height_lable = tk.Label(single,text="身高:",font=(12))
height_lable.place(x=150, y=200, width=50, height=20)
ent_in_height = tk.StringVar()
tk.Entry(single,width=20,textvariable=ent_in_height).place(x=200, y=200, width=150, height=20)
'''ent_in_height = tk.Entry(single,textvariable = tk.StringVar(),font = (12))
ent_in_height.place(x=200, y=200, width=150, height=20)'''
weight_lable = tk.Label(single,text="体重:",font=(12))
weight_lable.place(x=150, y=240, width=50, height=20)
ent_in_weight = tk.StringVar()
tk.Entry(single,width=20,textvariable=ent_in_weight).place(x=200, y=240, width=150, height=20)
'''ent_in_weight = tk.Entry(single,textvariable = tk.StringVar(),font = (12))
ent_in_weight.place(x=200, y=240, width=150, height=20)'''
def out_information():
in_username = X
conn = connet()
cur = conn.cursor()
sql = 'select * from 用户数据 where username=%s'
cur.execute(sql,in_username)
z = cur.fetchall()
conn.commit()
print(z)
ent_name.set(z[0][1])
ent_sex.set(z[0][2])
ent_age.set(z[0][3])
ent_in_height.set(z[0][4])
ent_in_weight.set(z[0][5])
#个人信息输入板块
def in_information():
print(X)
print(type(X))
in_username = X
in_name = ent_name.get()
in_sex = ent_sex.get()
in_age = ent_age.get()
in_height = ent_in_height.get()
in_weight = ent_in_weight.get()
conn = connet()
cur = conn.cursor()
sql = 'insert into 用户数据(username,nameval,sex,age,height,weight) values("%s","%s","%s","%s","%s","%s")'
cur.execute(sql%(in_username,in_name,in_sex,in_age,in_height,in_weight))
conn.commit()
conn.rollback()
tk.messagebox.showinfo(title="attention",message="个人信息输入成功")
menu.deiconify()
single.destroy()
btn_info_button = tk.Button(single,text="输入信息",command=in_information)
btn_info_button.place(x=200,y=350,width=60,height=45)
btn_inout_button = tk.Button(single,text="输出个人信息",command = out_information)
btn_inout_button.place(x=400,y=350,width=60,height=45)
single.mainloop()
为啥,套在函数里面,数据到数据库里只能显示username,其他的几项都没有也不是空,输出既不报错文本框也不显示出来。但是这部分单独拿出来配上包,都可以运行?ps:输入的部分昨天晚上好好的,今天啥也没动就不行了。