求助:tkinter界面制作,现在想绑定回车登录,希望大家帮助!!!现在不点回车也会执行绑定的函数,怎么办啊(

import tkinter
from socket import *
from tkinter import ttk
from tkinter import messagebox# name = ''def hello_screen():hello = tkinter.Tk()hello.title('实验室管理系统--管理员版')hello.geometry('417x500')img = tkinter.PhotoImage(file="./sdw.png")img1 = tkinter.PhotoImage(file="./R-C(1).png")img2 = tkinter.PhotoImage(file="./bbd_Convert.gif")laaa = tkinter.Label(hello, image=img2)laaa.place(x=1, y=0)label1 = tkinter.Label(hello, image=img1)label1.place(x=1, y=0)label2 = tkinter.Label(hello, text='用户名')label2.place(y=270, x=30)input1 = tkinter.Entry(hello, width=35)input1.place(x=75, y=275, height=20)xVariable = tkinter.StringVar()com = ttk.Combobox(hello, textvariable=xVariable)  # #创建下拉菜单com.pack()  # #将下拉菜单绑定到窗体com["value"] = ("课题组长", "导师")com.current(0)com.place(x=75, y=310)law = tkinter.Label(hello, text='身份')law.place(x=30, y=310)img3 = tkinter.PhotoImage(file="./R-C1(1).png")immg = tkinter.PhotoImage(file="./sxs.png")# name1 = "欢迎使用!" + namedef qwe(*args):def add_vacc_info():add_vacc_info = tkinter.Toplevel(hello)add_vacc_info.title('添加疫苗信息')add_vacc_info.geometry("600x400")tkinter.Label(add_vacc_info, image=immg).place(x=0, y=0)tkinter.Label(add_vacc_info, text='   学生姓名:', font=("Arial", 9), bg='#FFFEFA').place(x=80, y=60)tkinter.Label(add_vacc_info, text='   学生年龄:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=90)tkinter.Label(add_vacc_info, text='   学生性别:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=120)tkinter.Label(add_vacc_info, text='   学生编号:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=150)tkinter.Label(add_vacc_info, text='   学生成绩:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=180)tkinter.Label(add_vacc_info, text='   学生宿舍:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=210)tkinter.Label(add_vacc_info, text='   学生座位:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=240)tkinter.Label(add_vacc_info, text='   学生政治面貌:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=270)# tkinter.Label(add_vacc_info, text='学生政治面貌:', font=('Arial', 9), bg='#FFFEFA').place(x=80, y=300)entry1 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry2 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry3 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry4 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry5 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry6 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry7 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)entry8 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)# entry9 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)add_vacc_info.update()entry1.pack()entry2.pack()entry3.pack()entry4.pack()entry5.pack()entry6.pack()entry7.pack()entry8.pack()# entry9.pack()entry1.place(x=180, y=60, width=350)entry2.place(x=180, y=90, width=350)entry3.place(x=180, y=120, width=350)entry4.place(x=180, y=150, width=350)entry5.place(x=180, y=180, width=350)entry6.place(x=180, y=210, width=350)entry7.place(x=180, y=240, width=350)entry8.place(x=180, y=270, width=350)# entry9.place(x=180, y=300, width=350)def add():text1 = entry1.get()text2 = entry2.get()text3 = entry3.get()text4 = entry4.get()text5 = entry5.get()text6 = entry6.get()text7 = entry7.get()text8 = entry8.get()# text9 = entry9.get()# content = "INSERT INTO vaccine_info (" \#           "vaccine_num, vaccine_name, company_name, company_num, size, buy_price, pre_sale_price, " \#           "limit_up, limit_down" \#           ")" \#           " VALUES (%s, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');" % (#               text1, text2, text3, text4, text5, text6, text7, text8, text9)# self.connect_DBS(database="vaccine_info", content=content)tkinter.messagebox.showinfo(title="信息", message="数据添加成功!")def clear():entry1.delete(0, "end")entry2.delete(0, "end")entry3.delete(0, "end")entry4.delete(0, "end")entry5.delete(0, "end")entry6.delete(0, "end")entry7.delete(0, "end")entry8.delete(0, "end")# entry9.delete(0, "end")tkinter.messagebox.showinfo(title="信息", message="数据已清空,请继续添加!")tkinter.Button(add_vacc_info, text="添加", bg='white', font="Arial,9", width=9, height=0,command=add).place(x=400, y=360)tkinter.Button(add_vacc_info, text="清空", bg='white', font="Arial,9", width=9, height=0,command=clear).place(x=160, y=360)def add_vaccine_distr_info():add_vaccine_distr_info = tkinter.Toplevel(hello)add_vaccine_distr_info.title('添加作业信息')add_vaccine_distr_info.geometry('600x400')tkinter.Label(add_vaccine_distr_info, bg='#C3D1B6').place(x=0, y=0, width=10000, height=1000)tkinter.Label(add_vaccine_distr_info, text=' 作业名称:', font='Arial, 9', bg='#C3D1B6').place(x=80, y=60)tkinter.Label(add_vaccine_distr_info, text=' 日期:', font='Arial, 9', bg='#C3D1B6').place(x=80, y=90)tkinter.Label(add_vaccine_distr_info, text=' 作业编号:', font='Arial, 9', bg='#C3D1B6').place(x=80, y=120)tkinter.Label(add_vaccine_distr_info, text=' 导师名称:', font='Arial, 9', bg='#C3D1B6').place(x=80, y=150)tkinter.Label(add_vaccine_distr_info, text=' 导师编号:', font='Arial, 9', bg='#C3D1B6').place(x=80, y=180)tkinter.Label(add_vaccine_distr_info, text=' 数量:', font='Arial, 9', bg='#C3D1B6').place(x=80, y=210)entry1 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)entry2 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)entry3 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)entry4 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)entry5 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)entry6 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)entry1.pack()entry2.pack()entry3.pack()entry4.pack()entry5.pack()entry6.pack()entry1.place(x=180, y=60, width=350)entry2.place(x=180, y=90, width=350)entry3.place(x=180, y=120, width=350)entry4.place(x=180, y=150, width=350)entry5.place(x=180, y=180, width=350)entry6.place(x=180, y=210, width=350)add_vaccine_distr_info.update()def options():hello.withdraw()options = tkinter.Toplevel(hello)options.title('功能选项')options.geometry("613x800")img5 = tkinter.PhotoImage(file='./R-C11(1).png')options.update()options.overrideredirect(1)options.resizable(False, False)lyt = tkinter.Label(options, image=img)lyt.place(x=0, y=0)tkinter.Label(options, text='欢迎使用实验室管理系统!', font=("KaiTi", 39)).place(x=0, y=15)tkinter.Button(options, text='新建学生信息', bg='#ECECEC', font="Arial,12", width=20, height=2,command=add_vacc_info, relief='flat').place(x=5, y=100)tkinter.Button(options, text='新建学生作业', bg='#ECECEC', font="Arial,12", width=20, height=2,command=add_vaccine_distr_info, relief='flat').place(x=5, y=160)tkinter.Button(options, text='退出管理系统', bg='#ECECEC', relief='flat', font="Arial,12", width=20, height=2,command=lambda: qui_t()).place(x=5, y=220)# tkinter.Button(options, image=img5, width=16, height=16, command=lambda: quit()).place(x=59, y=78)# tkinter.Button(options, text='新建疫苗养护信息', bg='white', font="Arial,12", width=20, height=2,#                command=add_vaccine_maintenance_info).place(x=100, y=220)# tkinter.Button(options, text='新建接种人员信息', bg='white', font="Arial,12", width=20, height=2,#                command=add_vaccination_person_info).place(x=100, y=280)# tkinter.Button(options, text='查询学生作业信息', bg='white', font="Arial,12", width=20, height=2,#                command=vaccine_distr_info_query).place(x=100, y=340)# tkinter.Button(options, text='查询学生住宿信息', bg='white', font="Arial,12", width=20, height=2,#                command=vaccination_maintenance_info_query).place(x=320, y=100)# tkinter.Button(options, text='查询核酸检测信息', bg='white', font="Arial,12", width=20, height=2,#                command=vaccination_person_info_query).place(x=320, y=160)# tkinter.Button(options, text='查询接种疫苗信息', bg='white', font="Arial,12", width=20, height=2,#                command=vaccine_info_query).place(x=320, y=220)# tkinter.Button(options, text='修改学生信息', bg='white', font="Arial,12", width=20, height=2,#                command=modify_vaccine_info).place(x=320, y=280)# tkinter.Button(options, text='删除学生信息', bg='white', font="Arial,12", width=20, height=2,#                command=del_vaccine_info).place(x=320, y=340)def run():options()run()hello.bind('<Enter>', qwe)def qui_t():hello.destroy()button = tkinter.Button(hello, image=img3, relief='flat', command=lambda: qwe())button.place(x=250, y=400)imp2 = tkinter.PhotoImage(file="./9071.png_860(1)(1).png")img4 = tkinter.Button(hello, image=imp2, relief='flat', command=lambda: qui_t())img4.place(x=100, y=403)hello.mainloop()hello_screen()

本文链接:https://my.lmcjl.com/post/19330.html

展开阅读全文

4 评论

留下您的评论.