找回密码
 会员注册
查看: 27|回复: 0

python设计一个登录界面

[复制链接]

2万

主题

0

回帖

7万

积分

超级版主

积分
71089
发表于 2024-9-9 20:43:56 | 显示全部楼层 |阅读模式
游戏登录界面1.设计登录界面1.1导入需要的工具包1.2窗口显示1.3登录界面图片显示1.4用户名设置默认值1.5标签按钮输入框显示2.登录功能实现2.1用户数据存储2.2登录和注册2.2.1登录功能实现注册功能实现1.设计登录界面1.1导入需要的工具包importtkinterastkfromPILimportImage,ImageTkimportpicklefromtkinterimportmessageboximportsubprocess123451.2窗口显示window=tk.Tk()window.title("Welcome")window.geometry('500x600')1231.3登录界面图片显示image=Image.open("welcome.gif")photo=ImageTk.PhotoImage(image)121.4用户名设置默认值value="GaoYue"entry_var=tk.StringVar(window)entry_var.set(value)1231.5标签按钮输入框显示label1_image=tk.Label(window,image=photo)label1_image.place(x=10,y=10)label2=tk.Label(window,text='Username',width=10,height=5)label2.place(x=40,y=130)label3=tk.Label(window,text='password',width=10,height=5)label3.place(x=40,y=180)label4=tk.Entry(window,width=30,bd=5)label4.place(x=140,y=210)label5=tk.Entry(window,textvariable=entry_var,width=30,bd=5)label5.place(x=140,y=160)button1=tk.Button(window,text='Loign',width=10,command=usr_login)button1.place(x=140,y=280)button2=tk.Button(window,text='Signup',width=10,command=usr_sign_up)button2.place(x=250,y=280)1234567891011121314152.登录功能实现2.1用户数据存储defusr_login():usr_name=label5.get()usr_pwd=label4.get()print(usr_name)try:withopen("usrs_info.pickle",'rb')asusr_file:print("1")usrs_info=pickle.load(usr_file)print(usrs_info)exceptFileNotFoundError:withopen("usrs_info.pickle",'wb')asusr_file:print("2")usrs_info={'admin':'admin'}pickle.dump(usrs_info,usr_file)12345678910111213142.2登录和注册2.2.1登录功能实现print("ok")print("usr_name:",usr_name)ifusr_nameinusrs_info:print("3")ifusr_pwd==usrs_info[usr_name]:tk.messagebox.showinfo(title="Welcome",message="Howareyou"+usr_name)tk.messagebox.showinfo(title="GameStart",message="Let'sstartthegame!")subprocess.run(["python","井字棋.py"])else:tk.messagebox.showerror(message="Error,yourpasswordiswrong,tryagain.")else:print("4")is_sign_up=tk.messagebox.askyesno(title="Welcome",message="Youhavenotsignupyet.signuptoday?")12345678910111213注册功能实现defsign_up():nn=entry9.get()np=entry10.get()npf=entry11.get()withopen('usrs_info.pickle','rb')asusr_file:exist_usr_info=pickle.load(usr_file)ifnp!=npf:tk.messagebox.showerror("Error","Theuserhasalreadysignedup!")elifnninexist_usr_info:print("已经注册过了")tk.messagebox.showerror("Error","Theuserhasalreadysignedup!")else:exist_usr_info[nn]=npwithopen("usrs_info.pickle","wb")asusr_file:pickle.dump(exist_usr_info,usr_file)tk.messagebox.showinfo("Welcome","Youhavesuccessfullysignedup!")window.destroy()button3=tk.Button(window,text='Signup',width=10,command=sign_up)button3.place(x=140,y=150)print("开始注册")1234567891011121314151617181920
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2025-1-9 06:01 , Processed in 0.862498 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表