Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson18-diy1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d352b16c
authored
May 02, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
12c405d1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletions
my_app.py
my_app.py
View file @
d352b16c
import
tkinter
import
tkinter
from
tkinter
import
messagebox
# 从tkinter模块中导入messagebox组件
import
json
#导入json模块
def
login_to_reg
():
# 登录界面转注册界面
def
login_to_reg
():
# 登录界面转注册界面
app_login
.
root
.
destroy
()
# 调用destroy()关闭窗口
app_login
.
root
.
destroy
()
# 调用destroy()关闭窗口
...
@@ -13,7 +15,22 @@ def reg_to_login(): # 注册界面转登录界面
...
@@ -13,7 +15,22 @@ def reg_to_login(): # 注册界面转登录界面
app_login
.
show
()
# 调用show()方法打开app_login
app_login
.
show
()
# 调用show()方法打开app_login
def
register
():
# 注册验证
def
register
():
# 注册验证
pass
name
,
password1
,
password2
=
app_reg
.
get_input
()
# 创建三个变量接收返回的结果
if
name
==
""
or
password1
==
""
or
password2
==
""
:
# if判断注册信息的填写是否完整
messagebox
.
showwrning
(
"警告"
,
"请填写完整的注册资料"
)
# ⬆通过messagebox组件调用showwarning()方法进行提示
elif
name
in
users
:
# 继续判断如果提交的用户名已被注册
messagebox
.
showwrning
(
"错误"
,
"用户名已存在!"
)
# 提示
elif
password1
!=
password2
:
# 继续判断如果用户名没有被注册
messagebox
.
showwrning
(
"错误"
,
"两次密码不一致!"
)
# 提示
else
:
# 否则
users
[
name
]
=
password1
# 注册信息合格
content
=
json
.
dumps
(
users
)
# 将字典转换为json字符串
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
file
.
write
(
content
)
# 将用户信息重写入"user.txt"文本里
# 注册成功,转到登录界面
messagebox
.
showinfo
(
"成功"
,
"注册成功"
)
# 提示注册成功
reg_to_login
()
# 调用reg_to_login()函数转入登录界面
def
login
():
# 登录验证
def
login
():
# 登录验证
pass
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment