原文链接

Emmmm…懒癌晚期的我…终于再次开始写blog了…

拜无穷无尽的考试 ~~ 和懒~~ 所赐…10天没有更新了!

感谢大家的催更吖!

| 程序语言 | Python | | —- | —- | | 工具/原料 | 电脑,Tkinter | | 其它 | 懒癌晚期患者,催更… 请勿温柔 |

某人:Talk is cheap,show me the code!【是这样说的吗?】

我:好叭~ code来啦!接好,小心砸你脸上!

介个是 上篇链接~:

【Python】从0到1:从头开始写打砖块小游戏)
今日份Code ):

  1. # 初始化
  2. import tkinter as tk
  3. import tkinter.messagebox
  4. import pickle
  5. window = tk.Tk()
  6. # 登陆界面
  7. window.title('登录界面~')
  8. window.geometry('400x300')
  9. tk.Label(window, text='用户名~:').place(x=100,y=100)
  10. tk.Label(window, text='密码~:').place(x=100, y=140)
  11. var_usr_name = tk.StringVar()
  12. enter_usr_name = tk.Entry(window, textvariable=var_usr_name)
  13. enter_usr_name.place(x=160, y=100)
  14. var_usr_pwd = tk.StringVar()
  15. enter_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*')
  16. enter_usr_pwd.place(x=160, y=140)
  17. #登录
  18. def usr_log_in():
  19. #输入框内容
  20. usr_name = var_usr_name.get()
  21. usr_pwd = var_usr_pwd.get()
  22. try:
  23. with open('usr_info.pickle', 'rb') as usr_file:
  24. usrs_info=pickle.load(usr_file)
  25. except:
  26. with open('usr_info.pickle', 'wb') as usr_file:
  27. usrs_info={'admin':'admin'}
  28. pickle.dump(usrs_info, usr_file)
  29. # 判断用户输入
  30. if usr_name in usrs_info:
  31. if usr_pwd == usrs_info[usr_name]:
  32. tk.messagebox.showinfo(title='Welcome!', message='Hi~ o(* ̄▽ ̄*)ブ,登录成功啦~')
  33. else:
  34. tk.messagebox.showerror(message='emmm...账号不存在,请检查输入~ 未注册请先注册哦~')
  35. # 用户名 & 密码不能为空
  36. elif usr_name == '' or usr_pwd == '':
  37. tk.messagebox.showerror(message='用户名和密码不能为空哦~')
  38. def usr_sign_quit():
  39. window.destroy()
  40. def usr_sign_up():
  41. def signtowcg():
  42. NewName = new_name.get()
  43. NewPwd = new_pwd.get()
  44. ConfirPwd = pwd_comfirm.get()
  45. try:
  46. with open('usr_info.pickle', 'rb') as usr_file:
  47. exist_usr_info = pickle.load(usr_file)
  48. except FileNotFoundError:
  49. exist_usr_info = {}
  50. if NewName in exist_usr_info:
  51. tk.messagebox.showerror(message='用户名被别人占用啦!')
  52. elif NewName == '' and NewPwd == '':
  53. tk.messagebox.showerror(message='用户名和密码不能为空哦~')
  54. elif NewPwd != ConfirPwd:
  55. tk.messagebox.showerror(message='emmm...密码前后不一致...')
  56. else:
  57. exist_usr_info[NewName] = NewPwd
  58. with open('usr_info.pickle', 'wb') as usr_file:
  59. pickle.dump(exist_usr_info, usr_file)
  60. tk.messagebox.showinfo(message='注册成功啦!o(* ̄▽ ̄*)ブ')
  61. window_sign_up.destroy()
  62. # 新建注册窗口
  63. window_sign_up = tk.Toplevel(window)
  64. window_sign_up.geometry('400x300')
  65. window_sign_up.title('注册界面~' )
  66. # 注册编辑框
  67. new_name = tk.StringVar()
  68. new_pwd = tk.StringVar()
  69. pwd_comfirm = tk.StringVar()
  70. tk.Label(window_sign_up, text='用户名~:').place(x=90,y=50)
  71. tk.Entry(window_sign_up, textvariable=new_name).place(x=160, y=50)
  72. tk.Label(window_sign_up, text='密码~:').place(x=90,y=100)
  73. tk.Entry(window_sign_up, textvariable=new_pwd, show='*').place(x=160, y=100)
  74. tk.Label(window_sign_up, text='确认密码~:').place(x=90, y=150)
  75. tk.Entry(window_sign_up, textvariable=pwd_comfirm, show='*').place(x=160, y=150)
  76. # 确认注册
  77. bt_confirm = tk.Button(window_sign_up, text='确定~', command=signtowcg).place(x=180,y=220)
  78. #登录 注册按钮
  79. bt_login = tk.Button(window,text='登录~',command=usr_log_in)
  80. bt_login.place(x=120,y=230)
  81. bt_signup = tk.Button(window,text='注册~',command=usr_sign_up)
  82. bt_signup.place(x=190,y=230)
  83. bt_logquit = tk.Button(window,text='退出~',command=usr_sign_quit)
  84. bt_logquit.place(x=260,y=230)
  85. window.mainloop()

并不美腻的效果图~(能力所限【捂脸】)

【Python】从0到1: 100行代码制作注册 _ 登陆界面!【可直接copy   运行哦~】 - 图1

附 · Dream Builder 筑梦者

如果你也热爱Python,热爱开源,那么,加入我们吧!

GitHub搜索 “筑梦者” 发送加入申请即可~

若想 了解详细信息,CSDN搜索并私信 “小曹162020”,”九亿少男的兄弟” ,”Micraow Peng” 即可了解详细信息~

也可以直接在 评论区👇👇👇留下你的GitHub号哦

欢迎您的加入~