下面是登录模块的代码,运行之后在登录窗口中输入用户名、密码,但点击登录没有反应。运行了一下感觉应该是执行sql语句的问题,但是实在不知道怎么改,求指点。
def usr_login():
usr_name = entry_user.get()
usr_pwd = entry_passwd.get()
index = combobox_login.current()
if index==0:
sql = """select * from dbo.student where 学籍号 = "%s" and 学籍号 = "%s" """ % (usr_name,usr_pwd)
if usr_name and usr_pwd: # 判断用户名和密码是否为空
connect = pymssql.connect('127.0.0.1', 'sa', '001226', 'scoresystem')
cur = connect.cursor()
try:
cur.execute(sql)
results = cur.fetchall()
print(results)
if results: # 察看用户名和密码是否存在
window.destroy()
else:
tk.messagebox.showinfo(message = '用户名或密码错误,请重试!')
except Exception as e:
connect.rollback()
finally:
connect.close() # 关闭连接
else:
tk.messagebox.showinfo(message = '用户名或密码不能为空,请重试!')
else:
sql = """select * from dbo.worker where 身份标识 = "%s" and 密码 = "%s" """ % (usr_name,usr_pwd)
if usr_name and usr_pwd: # 判断用户名和密码是否为空
connect = pymssql.connect('127.0.0.1', 'sa', '001226', 'scoresystem')
cur = connect.cursor()
try:
cur.execute(sql)
results = cur.fetchall()
print(results)
if results: # 察看用户名和密码是否存在
window.destroy()
else:
tk.messagebox.showinfo(message = '用户名或密码错误,请重试!')
except Exception as e:
connect.rollback()
finally:
connect.close() # 关闭连接
else:
tk.messagebox.showinfo(message = '用户名或密码不能为空,请重试!')
#登录界面
#初始化一个window界面
window = tk.Tk()
window.title('体测成绩管理系统')
window.geometry('450x300')
#插入背景图片
#canvas = tk.Canvas(window, height=300, width=500)
#image_file = tk.PhotoImage(file="C:\\Users\\Lenovo\\Desktop\\体测数据\\logo.png")
#image = canvas.create_image(0, 0, anchor='nw', image=image_file)
#canvas.pack(side='top')
#登录界面代码实现
tk.Label(window,text = '用户名 :').place(x =80,y = 90)
tk.Label(window,text = '密码 :').place(x =80,y = 130)
tk.Label(window,text = '登录身份 :').place(x =80,y = 170)
entry_user = tk.StringVar()
entry_passwd = tk.StringVar()
entry_usr_name = tk.Entry(window,textvariable = entry_user)
entry_usr_name.place(x = 180,y = 90)
entry_usr_pwd = tk.Entry(window,textvariable = entry_passwd,show ='*')
entry_usr_pwd.place(x = 180,y = 130)
comvalue=tk.StringVar() #登录身份下拉选框
combobox_login = ttk.Combobox(window,textvariable=comvalue,width=17)
combobox_login["values"]=("学生","管理员")
combobox_login.current(0) #选择第一个
combobox_login.place(x=180, y=170)
btn_login = tk.Button(window,text = '登录',command = usr_login) #登录界面按钮
btn_login.place(x = 200,y = 220)
window.mainloop()