|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from tkinter import *
- import pickle
- import 功能 as fun
- def Login_interface():
- global root
- root = Tk()
- screenWidth = root.winfo_screenwidth() # 获取显示区域的宽度
- screenHeight = root.winfo_screenheight() # 获取显示区域的高度
- width = 480# 设定窗口宽度
- height = 260 # 设定窗口高度
- left = (screenWidth - width) / 2
- top = (screenHeight - 60 - height) / 2
- root.geometry("%dx%d+%d+%d" % (width, height, left, top))
- root.title('登录')
- frame1 = Frame(root)
- frame2 = Frame(root)
- global photo
- photo = PhotoImage(file = '图.png')
- imglabel = Label(frame1,image=photo).pack()
- thelabel1 = Label(frame2,text='账号:').grid(row=0 ,column=0)
- thelabel2 = Label(frame2,text='密码:').grid(row=1 ,column=0)
- global e1
- global e2
- e1 = Entry(frame2)
- e2 = Entry(frame2)
- e1.grid(row=0, column=1, padx=10, pady=5)
- e2.grid(row=1, column=1, padx=10, pady=5)
- thebutton1 = Button(frame2,text='安全登录', width=10,command=enter).grid(row=2,column=0, padx=10, pady=30, sticky=W)
- thebutton2 = Button(frame2,text='退出', width=10,command=root.quit).grid(row=2, column=1, padx=10, pady=30, sticky=E)
- frame1.grid(row=0 ,column=0)
- frame2.grid(row=0 ,column=1)
- def enter():
- a = {}
- f = open("使用者.pkl",'rb')
- a = pickle.load(f)
- f.close()
- global e1
- global e2
- name = e1.get()
- password = e2.get()
- if (name in a):
- if (password == a[name]):
- global root
- root.destroy()
- fun.fuction()
- else:
- e1.delete(0,END)
- e1.delete(0,END)
- error()
- def error():
- master = Toplevel()
- screenWidth = master.winfo_screenwidth() # 获取显示区域的宽度
- screenHeight = master.winfo_screenheight() # 获取显示区域的高度
- width = 680# 设定窗口宽度
- height = 400 # 设定窗口高度
- left = (screenWidth - width) / 2
- top = (screenHeight - 60 - height) / 2
- master.geometry("%dx%d+%d+%d" % (width, height, left, top))
- master.title("输入有误!!!")
- frame1 = Frame(master)
- frame2 = Frame(master)
- global e_photo
- e_photo = PhotoImage(file='图1.png')
- thelabel1 = Label(frame1,text="您所输入的账号或密码有误,请重新输入!!!",image=e_photo,
- compound=CENTER,padx=10,pady=10,font=("微软雅黑", 20),fg="black").pack()
- thebutton = Button(frame2,text='OK',width=10,command=master.destroy).pack()
- frame1.pack()
- frame2.pack()
- if __name__ == "__main__":
- Login_interface()
- mainloop()
复制代码
这个程序的图片和输入框是分开的,有大佬能指点一下怎么让图片成为背景,输入框加载在图片上吗
|
|