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
ee7b0e8f
authored
May 22, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
65d71c86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
9 deletions
my_app.py
user.txt
my_app.py
View file @
ee7b0e8f
import
tkinter
from
tkinter
import
messagebox
import
json
#为后续导入模块
with
open
(
'user.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
#打开user文件进行读取
info
=
f
.
read
()
#读取数据
users
=
json
.
loads
(
info
)
#把json数据转化为python字典
def
login_to_reg
():
# 登录界面转注册界面
pass
app_login
.
root
.
destroy
()
#关闭窗口
global
app_reg
#把局部变量转换为全局变量
app_reg
=
My_register
()
#调用方法打开页面
app_reg
.
show
()
#让页面显示出来
def
reg_to_login
():
# 注册界面转登录界面
pass
app_reg
.
root
.
destroy
()
#关闭注册窗口
global
app_login
#把局部变量转换为全局变量
app_login
=
My_login
()
#打开登录窗口
app_login
.
show
()
#让页面显示出来
def
register
():
# 注册验证
pass
name
,
password1
,
password2
=
app_reg
.
get_input
()
#读取用户填写的信息
if
name
==
''
or
password1
==
''
or
password2
==
''
:
#盘对岸数据是否为空
messagebox
.
showwarning
(
'警告'
,
'请填写完整的信息'
)
#错误提示框
elif
name
in
users
:
#判断用户名是否已存在
messagebox
.
showwarning
(
'错误'
,
'用户名已存在'
)
#错误提示框
elif
password1
!=
password2
:
#判断两次密码输入的是否一致
messagebox
.
showwarning
(
'错误'
,
'两次输入的密码不一致'
)
#错误提示框
else
:
#用户输入信息没有问题
users
[
name
]
=
password1
content
=
json
.
dumps
(
users
)
#把users转化为josn数据
with
open
(
'user.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
content
)
#把转化好的数据储存在user文件里面
#注册成功返回到登录页面
messagebox
.
showinfo
(
'成功'
,
'注册成功'
)
reg_to_login
()
#打开登录窗口
def
login
():
# 登录验证
pass
name
,
password
=
app_login
.
get_input
()
#获取到数据
pwd
=
users
.
get
(
name
)
#查找用户名是否在users里面
if
pwd
==
password
:
messagebox
.
showinfo
(
'成功'
,
'登录成功'
)
else
:
messagebox
.
showwarning
(
'错误'
,
'用户名或密码错误'
)
class
My_login
():
# 登录窗口
def
__init__
(
self
):
...
...
user.txt
View file @
ee7b0e8f
{"admin": "123456"}
\ No newline at end of file
{"admin": "123456", "111": "111", "1111": "1111", "22222": "22222"}
\ No newline at end of file
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