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