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
e6faea14
authored
Aug 20, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
145fe74a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
9 deletions
my_app.py
user.txt
my_app.py
View file @
e6faea14
import
tkinter
import
tkinter
from
tkinter
import
messagebox
#载入json模块
import
json
#读取user.txt的内容,并转换为字典
with
open
(
"user.txt"
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
info
=
f
.
read
()
users
=
json
.
loads
(
info
)
def
login_to_reg
():
# 登录界面转注册界面
def
login_to_reg
():
# 登录界面转注册界面
pass
#关闭登录窗口 窗口对象.destroy()
app_login
.
root
.
destroy
()
#生成一个全局变量app_reg,用来实例化注册界面
global
app_reg
app_reg
=
My_register
()
#调用注册界面的show()方法来让窗口显示出来
app_reg
.
show
()
def
reg_to_login
():
# 注册界面转登录界面
def
reg_to_login
():
# 注册界面转登录界面
pass
#关闭注册窗口,窗口对象.destroy()
app_reg
.
root
.
destroy
()
#生成一个全局变量app_login,用来实例化登录界面
global
app_login
app_login
=
My_login
()
app_login
.
show
()
def
register
():
# 注册验证
def
register
():
# 注册验证
pass
#先要获得账号,密码,确认密码
name
,
password
,
epassword
=
app_reg
.
get_input
()
#三条有任意一条为空
if
name
==
""
or
password
==
""
or
epassword
==
""
:
#messgebox.showerror(标题,提示信息) 功能:报一个错误信息
messagebox
.
showerror
(
"错误"
,
"注册信息不能为空"
)
elif
password
!=
epassword
:
messagebox
.
showwarning
(
"警告"
,
"两次密码不一致"
)
elif
name
in
users
:
messagebox
.
showwarning
(
"警告"
,
"账号已被注册"
)
else
:
users
[
name
]
=
password
count
=
json
.
dumps
(
users
)
with
open
(
"user.txt"
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
count
)
messagebox
.
showinfo
(
"成功"
,
"注册成功"
)
reg_to_login
()
def
login
():
# 登录验证
def
login
():
# 登录验证
pass
pass
...
@@ -103,5 +137,5 @@ class My_register(): # 注册窗口
...
@@ -103,5 +137,5 @@ class My_register(): # 注册窗口
self
.
password2
=
self
.
e3
.
get
()
self
.
password2
=
self
.
e3
.
get
()
return
self
.
name
,
self
.
password1
,
self
.
password2
return
self
.
name
,
self
.
password1
,
self
.
password2
app_login
=
My_login
()
app_login
=
My_login
()
#登录窗口
app_login
.
show
()
app_login
.
show
()
#调用显示模块
\ No newline at end of file
\ No newline at end of file
user.txt
View file @
e6faea14
{"admin": "123456"}
{"admin": "123456", "aaa": "789"}
\ 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